1

I've made a little snake game and exported it into a runnable JAR file through Eclipse.

It works perfect in machines with JDK installed (with regards to the environment variables and all that.)

But "normal" people don't have that installed, only the JRE that can be found here: http://java.com/en/download/index.jsp

This is insufficient to execute the JAR apparently. I've tried numerous approaches:

  • packeging libraries in Jar
  • Extracting libraries in Jar
  • Build with java 1.7
  • building with java 1.8
  • checked the build path to make sure the libraries is included.

At best I get a "Java Exception occured" on the other PC (the one with JDK installed). I've then tried to run the JAR on my own machine through cmd with the command...

java -jar fileName.jar

...in the hope that I would get an error log, but nope, it just runs the JAR like there's no problem.

Any ideas on how to make the JAR run on a machine with JRE installed?

Thanks in advance

J0e3gan
  • 8,740
  • 10
  • 53
  • 80
user3149569
  • 147
  • 1
  • 12
  • Check this out http://stackoverflow.com/questions/11033603/how-to-create-a-jar-with-external-libraries-included-in-eclipse – ben Aug 07 '14 at 15:06
  • 1
    What are the details of the error these users are getting? – E-Riz Aug 07 '14 at 15:07
  • what are the errors that you get? Did that machine has compatible JRE version ? – Thusitha Thilina Dayaratne Aug 07 '14 at 15:07
  • How to see those errors? The error message "Java Exception occured" comes from a JVM. – user3149569 Aug 07 '14 at 15:08
  • 2
    It sounds like you're using some class or tool only available in the JDK. Can you provide an [MCVE](http://stackoverflow.com/help/mcve) that demonstrates the problem? – Kevin Workman Aug 07 '14 at 15:09
  • 1
    The only thing that may help to answer is stacktrace please provide the stacktrace – SparkOn Aug 07 '14 at 16:27
  • i got no idea how to get the stackTrace. I've tried to just make a small program that just prints "Hello world" and tried to make it run on another pc. it didn't work. can't the JVM run java 8 or something? – user3149569 Aug 07 '14 at 17:32

3 Answers3

0

Check packr

Packages your JAR, assets and a JVM for distribution on Windows, Linux and Mac OS X

MLProgrammer-CiM
  • 17,231
  • 5
  • 42
  • 75
  • can you elaborate on this? it doesn't make much sense to me. – user3149569 Aug 07 '14 at 15:25
  • This tool packages your jar along with a virtual machine so you don't depend on the user or java version for your application. I'm not going to reproduce the instructions, which are available in the webpage. – MLProgrammer-CiM Aug 07 '14 at 16:36
  • 1
    And you may be new to SO but we don't downvote post because we don't understand them. Only when they're factually wrong or doesn't answer the question, which is not my case. This is not Reddit. – MLProgrammer-CiM Aug 07 '14 at 16:36
0

Appareantly, build for jre7 fixed the problem, why it can't run jre8, i don't know..

user3149569
  • 147
  • 1
  • 12
0

The JDK includes a tools.jar (among many others) which are omitted from the JRE. In your project expand the JRE System Libraries and make sure none of the libraries are coming from the a JDK.

Also adding some example text of the exact error you're seeing would really help us know what's going on. Stating "Java Exception occurred" is the equivalent of telling a doctor you don't feel well.

For what it's worth it's not a good idea to use classes from the JDK in your code as it has stricter licensing than the JRE.

cyber-monk
  • 5,470
  • 6
  • 33
  • 42
  • all i did was changing it from using jdk 1.8 to jre7, everything works perfectly now on systems that doesn't have the jdk installed. – user3149569 Aug 07 '14 at 17:57