-2

I have a Java console application which I can package into a jar file using IntelliJ, and can run the program with a bat or cmd file which has the following command:

java -jar main.jar

The problem with this is that my development machine (Windows) has the JAVA_HOME and PATH modified so that this works without issue.

Is there a way so that I can package the jar so that it can be opened without needing to modify the PATH?

I've tried looking all over and found questions on SO and other sites relating to building the jar, but it seems like all of these still require modifying the PATH variable.

Java's documentation says:

Making changes to the system PATH variable is not typically necessary for computers running Windows or Mac OS X. The instructions below are intended for advanced users or system administrators only.

If this is the case then how can others run the program if they are not an "advanced user" or "system administrator"?

Edit:

As an aside, I know this is possible because some jar files, like those which use the Swing framework are able to be run by just double-clicking on the jar and then the application opens.

Edit 2:

This article seems to be along the right path.

Edit 3:

This is kinda what I was looking for, however, it didn't work for me. The command I was trying on my existing jar was jar uvfm main.jar manifest.txt which returned updated manifest, but changed nothing.

Community
  • 1
  • 1
Kyle Falconer
  • 8,302
  • 6
  • 48
  • 68
  • I don't believe you'll be able to get the rights to ship a JRE with your application, but that's what you'd need to do. – Elliott Frisch Nov 21 '13 at 18:03
  • If a JRE is installed, the path should be set correctly (speaking from experience on Windows and on Mac OS Leopard (10.5.8)). ........ If no JRE is installed, then http://launch4j.sourceforge.net/ and similar tools can help. With this one, you can just add your *installed* JRE in a subfolder, and the user doesn't have to install a thing. I am not *sure*, but I believe I looked up if Oracle is ok with this kind of approach, and I think my finding was "yes". ........ Eventually, you may want to enable double-click start functionality: http://stackoverflow.com/a/32547250/3500521 – Dreamspace President Sep 13 '15 at 07:53

2 Answers2

0

No you cannot. They are system variables. The best thing to do is to write a shell script that will set these variables.

benjamin.d
  • 2,801
  • 3
  • 23
  • 35
  • 1
    I don't care if the `java` command is known by the OS. If Java is installed, then jar files should be associated with Java and should be able to be opened just like any other application, right? – Kyle Falconer Nov 21 '13 at 18:19
  • Not necesseraly. Bundle a JRE (if possible) as suggested or write a script. – benjamin.d Nov 21 '13 at 18:54
0

no. It should be able to understand 'java' command. For this path need to be set. But if you are planning to shift your jar as an application, you need to ship jre as well with your application. But i dont think this is what you want

Freaky Thommi
  • 756
  • 7
  • 18