开发者

Jar Can't Find Main Class

开发者 https://www.devze.com 2023-03-15 05:04 出处:网络
I get: Could not find the main class: org.dav.kin.Tester. Program will exit. when I attempt to run my jar file via java -jar tester.jar or java -classpath tester.jar org.dav.kin.Tester Does anyone kno

I get: Could not find the main class: org.dav.kin.Tester. Program will exit. when I attempt to run my jar file via java -jar tester.jar or java -classpath tester.jar org.dav.kin.Tester Does anyone know what is wrong and how to fix it? Below are additional details. Thanks.

Manifest File:

Manifest-Version: 1.0
Created-By: DKin
Class-Path: .
Main-Class: org.dav.kin.Tester

jar tf tester.jar

org/
org/dav/
org/dav/kin/
org/dav/kin/Tester.class
org/dav/kin/TesterCellRenderer.class
...
...
META-INF/
META-INF/MANIFEST.MF

UPDATE:

Jar file runs if I specify the system classpath, which contains the groovy-all-{version开发者_如何学C}.jar, like so: java -classpath tester.jar;"%CLASSPATH%" org.dav.kin.Tester Anyone know why I have to explicitly re-state the classpath (or more precisely, the groovy jar)?


Your jar file lacks a file with this name

/org/dav/kin/Tester.class

or you have special characters in your MANIFEST.MF file

MANIFEST.MF files have a particular syntax. It's best to use other tools to generate them; however some of the details I've encountered which increases the success of hand written files include:

  1. Always make sure the lines are less than 72 characters long.
  2. Always use \r\n (windows newline), even on non-windows systems.
  3. Verify that all whitespace characters are spaces.
  4. Verify that there are no nonprintable characters (htab, etc).
  5. Sometimes a blank line at the end of the file helps.


Is Tester.class' package declaration org.dav.kin?


You have indicated that the you are using Groovy. Groovy does compile down to Java class files but it still requires the groovy runtime libraries. You need to make sure groovy is on the classpath as well as your classes. Try this:

java -classpath tester.jar;groovy-all-1.8.0.jar org.dav.kin.Tester


Just in case. I just solve exactly the same problem. Instead of

Class-Path: .

in MANIFEST.MF

one should enumerate (with space) jars which are required in runtime, so it should be something like this:

Class-Path: groovy-all-2.4.5.jar relative/my-dependent-project-artifact.jar
0

精彩评论

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