[英]jar file not finding main class
After compiling a java program with javac
用javac
编译Java程序后
$ 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. 我将结果类和我在jar中使用的库包括在内,但是jar文件不会执行。
Running the java file on the command line works: 在命令行上运行java文件可以:
$ java -classpath javax.activation.jar:javax.mail.jar:. PriceEmailer
Sending...
Email sent!
Now I want to make an executable .jar
file. 现在,我想制作一个可执行的.jar
文件。 I placed the following in manifest.txt: 我将以下内容放在manifest.txt中:
Manifest-Version: 1.0
Main-Class: PriceEmailer
Class-Path: javax.activation.jar:javax.mail.jar:.
Creating the .jar
file: 创建.jar
文件:
$ 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: 运行.jar
文件:
$ java -jar PriceEmailer.jar
Error: Could not find or load main class PriceEmailer
Why can't the jar file execute? 为什么jar文件无法执行?
Note: The main
function is in the file PriceEmailer.java
which defines the PriceEmailer
class. 注意: main
功能在文件PriceEmailer.java
,该文件定义了PriceEmailer
类。
public static void main(String[] args) throws Exception {
The Class-path entries should be separated by spaces, not colons. 类路径条目应该用空格而不是冒号分隔。 See the specification . 请参阅规格 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.