简体   繁体   中英

Jar Can't Find Main Class

I get: Could not find the main class: org.dav.kin.Tester. Program will exit. 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}.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)?

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

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.

Tester.class的包声明是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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM