简体   繁体   中英

jar file not finding main class

After compiling a java program with javac

$ javac -classpath javax.mail.jar:javax.activation.jar:. PriceEmailer.java

I am including the resultant class and the libraries I used into a jar, however, the jar file will not execute.

Running the java file on the command line works:

$ java -classpath javax.activation.jar:javax.mail.jar:. PriceEmailer 
Sending...
Email sent!

Now I want to make an executable .jar file. I placed the following in manifest.txt:

Manifest-Version: 1.0
Main-Class: PriceEmailer
Class-Path: javax.activation.jar:javax.mail.jar:.

Creating the .jar file:

$ jar vcfm PriceEmailer.jar manifest.txt class/*
added manifest
adding: class/javax.activation.jar(in = 56290) (out= 50561)(deflated 10%)
adding: class/javax.mail.jar(in = 653275) (out= 617552)(deflated 5%)
adding: class/PriceEmailer.class(in = 4106) (out= 2205)(deflated 46%)

Running the .jar file:

$ java -jar PriceEmailer.jar 
Error: Could not find or load main class PriceEmailer

Why can't the jar file execute?

Note: The main function is in the file PriceEmailer.java which defines the PriceEmailer class.

public static void main(String[] args) throws Exception {

The Class-path entries should be separated by spaces, not colons. See the specification .

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