Java Application Launcher

覺得自已實在是學藝不精。

建了一個可執行的Jar檔後,使用command line啟動卻怎麼也動不了, 一直出現NoClassDefFoundError,即使設定ClassPath也沒用。

還是得請教Google大神,才知道使用java -jar是會忽略-cp的參數,只參考META-INF/MANIFEST.MF中設定的Class-Path:。

“When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.” (Java Application Launcher)

因此使用java -jar所參考的Shared Lib一定要放在Class-Path所設定的位置,否則會讀不到。

Example: How to execute myJar.jar

1) java -jar myJar.jar

META-INF/MANIFEST.MF 
Class-Path: lib/mySharedLib.jar ←Shared Lib must be put under this directory

java -jar myJar.jar

2) java (Windows Environment)

java -cp myJar.jar;.\lib\* my.test.MyMain

Reference: Java Application Launcher

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s