Reputation: 129
I have recently developed some java applications that i want others to run on their machines. I did some research and now know that to distribute java code you need to create .jar file. Well i did that, but when I am distributed those file it runs on some computers but on others it return an error saying: "Main class could not found".
Upvotes: 5
Views: 469
Reputation: 5653
The error message indicates that the JRE can't find your main class. From the comments it looks like you did not specify the manifest correctly. Is it contained inside a META-INF directory inside the jar? What does jar -tf my_jar.jar
tell you?
If you're worried about JRE versions, try specifying a lower target version in your javac command. You do this by adding -target xx
to your javac
invocation and possibly also -source xx
. Have a look at javac -help
for a description of the flags.
Upvotes: 0
Reputation: 105
Some of the SDKs (like Eclipse) have a function for the creating of jar-files. If you work one the console this will maybe help you to create stable jar-files:
'jar cfm className.jar MANIFEST.MF className.class'
Upvotes: 0
Reputation: 34367
Option1: Create a manifest file with entry as below and include in the jar:
Main-Class: MainProgram
Option2: Just mention your Main
class name while running the program e.g. if you jar
name is myprogram.jar
and main class is MainProgram
then run the program as below:
java -cp myprogram.jar MainProgram
If your MainProgram
takes some arguments, them pass them as well in the command line e.g.
java -cp myprogram.jar MainProgram argument1 argument2
Upvotes: 2