Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distributing java application

Tags:

java

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".

  1. Is there any problem with JRE version.
  2. How would a user know that on which version he/she should run the application.
  3. can i package the correct jre version with my app/jar file. how??
  4. Are jar files not compatible with other version of jre except in which they are compiled.
like image 359
anichhangani Avatar asked Nov 03 '22 11:11

anichhangani


1 Answers

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
like image 133
Yogendra Singh Avatar answered Nov 12 '22 12:11

Yogendra Singh