开发者

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

I am creating an executable jar file of a java project. I successfully created a sample jar file with Hello world class. I used following commands to create a jar:

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

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

The Con开发者_如何学JAVAtents of my manifest.mf are

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

This works fine.

Now when I use same procedure to create the jar of my project, I am getting mainClass not found error.

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?


In your manifest file you have to set the parameter

Main-Class
to the class witch contains the
public static void main(String[] args)
you wants to call.
Has I can imagine, you want to start with the
MyClass

Your mainfest should contains:

Main-Class: MyClass

Regards


You don't say what "your project" consists of. Remember that java cannot load jars from within a jar (atleast while using the -jar flag), so if you have any jar-dependencies you will have to "explode" them into classes/directory style layout.


I recommend to use Ant and Jar Task for this purpose. Ant makes it very easy for you to configure the attributes of the jar file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜