tags:

views:

103

answers:

3

Can I include the rt.jar in my executable jar file and double click to run it without installing java on the machine first ? I hope it to use that rt.jar in my jar to start it self, possible ? If not, any other way ?

A: 

The file rt.jar has Java classes in it (in the form of Java bytecode). In order to interpret the classes, you will need to have Java installed.

Topher Fangio
+1  A: 

Java needs a Java virtual machine (JVM/JRE whatever you want to call it) to run java applications. However, I'm not so sure you need Java to be installed, rather it just be present.

You could provide this alongside your JAR (with a batch file to run the JAR files - as there won't be associations if it's not installed) but it would seriously expand the size of your project.

There are licensing issues to address too.

Oli
I think this is the only right answer on this thread. You don't need to have Java installed in order to run Java if you ship its binaries with your app. It probably isn't the best approach, but it will work.
Ravi Wallau
+3  A: 

No, you need a java virtual machine. rt.jar is also interpreted by the virtual machine and is just the java class library.

If you're looking to turn the code native you might consider gcj which can convert java code to machine code and wrap it up in an exe as per gcc. However, I'm not sure what version of java gcj supports - I've read somewhere it isn't very recent.

It looks like Launch4j can include a bundled JRE, so you might consider this.

Ninefingers