Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

java - How do I run a JAR file in Ubuntu that was compiled on windows?

I compiled the Java project on Windows with java 1.8, it worked fine on my windows machine, then in my Ubuntu I set it up with Java 1.8 too, now Ubuntu says can’t find Main class, I researched the problem, didn’t help, I suspect it has something to do with the folder path, but i copied the entire project folder compiled by net-beans to my Ubuntu. my manifest file contents :

Manifest-Version: 1.0

X-COMMENT: Main-Class will be added automatically by build

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your manifest file doesn't list the main class as well as the class path dependencies. So that means when you run the jar, you have to run by providing the class path as well as the main program to run.

For e.g.

java -cp /path/to/my/jar/dependencies -jar file.jar com.package.of.my.main.class.MyMainClass "any arguments if any"

Or have your manifest file provide both the class path and the main class and just run

java -jar file.jar


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...