自升級到OSX Mountain Lion以來,我在設置eclipse和maven的環境變量時遇到了一些問題。如何將環境變量設置爲OSX Mountain Lion上的應用程序?
我的目標是在Eclipse中運行maven命令。該命令需要從遠程存儲庫下載工件(解析依賴關係)。該存儲庫通過HTTPS進行身份驗證。
我按照Guide to Remote repository access through authenticated HTTPS並將下面的行添加到我的.bash_profil。如果我在終端上運行maven,一切正常。
export MAVEN_OPTS="-Xmx512m -Djavax.net.ssl.trustStore=/Users/myUser/.knowncerts/trust.jks -Djavax.net.ssl.trustStorePassword=trustPwd"
但是,這隻適用於終端,不適用於應用程序。在以前OSX版本,你不得不把MAVEN_OPTS變量添加到
~/.MacOSX/environment.plist
(見Set environment variables on Mac OS X Lion)這個工作對OSX獅子完美。
但蘋果已經改變了這種行爲在山獅。我讀過了environment.plist不再支持,新的方法是編輯.app本身的Info.plist(Where are system environment variables set in Mountain Lion?)。看來你必須添加一個包含你所有變量的字典LSEnvironment。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSEnvironment</key>
<dict>
<key>M2_HOME</key>
<string>/usr/share/maven</string>
<key>MAVEN_OPTS</key>
<string>-Xmx512m -Djavax.net.ssl.trustStore=/Users/myUser/.knowncerts/trust.jks -Djavax.net.ssl.trustStorePassword=trustPwd</string>
</dict>
<key>CFBundleExecutable</key>
<string>eclipse</string>
<key>CFBundleGetInfoString</key>
<string>Eclipse 3.8 for Mac OS X, Copyright IBM Corp. and others 2002, 2011. All rights reserved.</string>
<key>CFBundleIconFile</key>
<string>Eclipse.icns</string>
<key>CFBundleIdentifier</key>
<string>org.eclipse.eclipse</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Eclipse</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.8</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>3.8</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleLocalizations</key>
<array>
<string>ar</string>
<string>cs</string>
<string>da</string>
<string>el</string>
<string>en</string>
<string>es</string>
<string>de</string>
<string>fi</string>
<string>fr</string>
<string>hu</string>
<string>it</string>
<string>iw</string>
<string>ja</string>
<string>ko</string>
<string>nl</string>
<string>no</string>
<string>pl</string>
<string>pt_BR</string>
<string>pt</string>
<string>ru</string>
<string>sv</string>
<string>tr</string>
<string>zh_HK</string>
<string>zh_TW</string>
<string>zh</string>
</array>
<key>Eclipse</key>
<array>
<string>-keyring</string>
<string>~/.eclipse_keyring</string>
<string>-showlocation</string>
</array>
</dict>
</plist>
正如您所看到的,我更改了Eclipse.app的Info.plist。但是這不起作用。我在Eclipse中啓動maven。但maven無法下載文物,因爲遠程存儲庫不受信任。我認爲Eclipse不使用我在Info.plist中定義的環境變量
您有任何建議如何解決此問題?
謝謝您的回答!
感謝您的快速回復! – Loki
不幸的是,這並沒有解決我的問題。當我用腳本啓動Eclipse時,它仍然不使用'MAVEN_OPTS'。但是,如果我導出了一個不同的'M2_HOME',Eclipse使用這個新的Maven-Home。 – Loki