FirmView
FirmView

Reputation: 3150

Creating executables from jar

I have created jar file in java. It uses some library files. so, the final structure I have is,

How to convert them into a single file, like an exe for windows? It should run in linux also, like (.sh files - NetBeans installer).

Upvotes: 0

Views: 166

Answers (4)

emesx
emesx

Reputation: 12755

Just make a JAR packed with all the library dependencies.

  1. If Maven is your build tool, check this SO question. There are similar solutions for other tools (Gradle etc).

  2. Some IDEs are also capable of this, for instance Netbeans and IntelliJ IDEA are.

Of course be sure, that the libraries you want to pack have a license that permits this.

Upvotes: 3

Jefferson
Jefferson

Reputation: 794

If you use Netbeans check this for join all jars in one, now when you have 1 jar you can create the exe with launch4j.

Upvotes: 2

Cubic
Cubic

Reputation: 15693

You have a few options here:

  • Compile to a native application with something like gcj. This isn't an option in many cases though (you'll see why if you look into it)

  • Have a modified java executable that runs your jar

  • Have an executable that runs your jar with java

If you can reasonably assume your clients have java installed, it should be fine to just deploy an executable jar though - on most Desktop OS'es the java distribution is set up to run executable jars in the expected fashion (i.e. by double clicking in Windows), and on those where it's not - well, people will likely know what java is and how to run jars.

Upvotes: 1

Random42
Random42

Reputation: 9159

Although this is possible it is against Java nature.

Java was designed as a portable language (write once, run anywhere); your .jar file contains Java bytecode, which is to be interpreted by the Java Virtual Machine at runtime; you can copy it to any architecture and it will run there.

An .exe file actually contains machine code specific language which is to be directly ran by the processors; this will not work on another architecture.

However there are different tools for your need like JarToExe or JSmooth.

Upvotes: 1

Related Questions