簡體   English   中英

創建jar時如何解決主類未找到異常?

[英]How to resolve main class not found exception while creating jar?

我正在創建Java項目的可執行jar文件。 我使用Hello World類成功創建了一個示例jar文件。 我使用以下命令創建了一個罐子:

 trail> javac -classpath "c:\Program Files\Java\jdk1.6.0_01\bin;" MyClass.java

 bin> jar cvfm MyJar.jar manifest.mf trail\*.class

我manifest.mf的內容是

  Manifest-Version: 1.0
  Created-By: 1.5.0_03 (Sun Microsystems Inc.)
  Main-Class: trial.MyClass

這很好。

現在,當我使用相同的過程創建項目的jar時,出現了MainClass not found錯誤。

EDIT
My project need 2 third party jar.
So I have compiled  My project by adding this jars in classpath.
I guess the problem is related with this jar file dependencies. 
Can anybody help me to solve this problem?

我建議為此使用Ant和Jar Task。 Ant使您很容易配置jar文件的屬性。

在清單文件中,您必須設置參數

Main-Class
到班上的女巫
 public static void main(String[] args) 
你想打電話。
我能想象到,您想從
 MyClass 

您的mainfest應該包含:

  主班:MyClass 

問候

您不會說“您的項目”由什么組成。 請記住,java無法從jar內加載jar(至少使用-jar標志時),因此,如果您具有任何jar依賴關系,則必須將其“分解”為類/目錄樣式布局。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM