Creating a .exe for a java project - java

I've developped a game during a Game Jam and I'd like to create an executable to distribute it to the other team members.
The game uses the slick2d and lwjgl library. I've tried to use JExePack, but the .exe file I get isn't runnable, I get an error while launching it.
Even the jar file gets me errors.
I'm only able to launch the game on the IDE. When I launch it with the command line : java -jar "game.jar", it obviously tells me that there's missing libraries, even if I indicate the path to the lib folder.
Is there an easy way to create an executable ?
Thanks in advance.

I think using a jar was a good idea.
You need to add every required jar in the classpath one-by-one for the jar to run properly.

Launch4J (http://launch4j.sourceforge.net/) is my favorite tool for that. You can just export an executable jar from your IDE and create an exe out of it. Creating an executable jar in Eclipse gives you the option to include all required libraries in it, which saves you from adding them manually when create the exe file. The minimal settings you need are:
Input (your executable jar)
Output (the .exe you want to create)
Minimum Java version (i.e. 1.6.0)
Thats it (as far as I remember)

If you want the exe you can use exe4j, it's a very useful tool, but i think using jars is better since you can run them on every platform. Anyway, when you export the jar, check on your ide's preferences if it automatically imports the libs. (for example, on eclipse you can pack the required libs into the exported jar)

You can use Luncher4j to create an exe file and convert the jar libraries to dll files.

Related

Create Java projects without eclipse?

Is there any way I can create Java projects using a simple text editor? Not an IDE like eclipse?
I want to be able to create .jar files without the assistance of an IDE, I have all the JDK commands installed already on my computer (such as javac)
I'd like to know what file structure I need, how I need to arrange my class files, what compilation steps I need to go through etc. to be able to create jar files.
Yes, completely doable (just not much fun once the project gets bigger).
I suggest if it's not a throwaway project, use a build tool like Maven or Gradle to manage your build process, so that you don't need to assemble classpaths and resources yourself, but still retain full control of the build and test lifecycle, without IDEs. This comes at a complexity cost, of course, but once it's set up life becomes easier.
See also How can I create an executable JAR with dependencies using Maven? or the Gradle docs about creating JARs
I'd highly recommend the standard Maven source directory layout too (src/main, src/test etc) as it's both commonplace and makes for easy integration with the above tools.
Follow the below steps to create a jar file
Compile the java source using javac
Create a manifest file (if main exists) to identify main class
Use the below command to create a jar file
jar -cvfm *.class
Yeah. You can create your project structure without an IDE. But it's time consuming and you have to do everything.
To talk about creating JAR, you don't want any extra software. You can use jar utility, which comes with JDK.
Here are steps to create jar:
Compile classes which you want to in jar
Create manifest file (.mf). It's needed if you want to make jar as executable. If you want to bundle classes only together, then no need. (eg. Dependency jar)
Go to command prompt and execute following command "jar cvf MyJarName.jar *.class". Make sure java is set in environment path and you're inside the directory of classes.
cvf means "create a jar; show verbose output; specify the output jar file name.
That's all. If you want to include any folders inside jar then you can use folder name in above command after classes and it must be separated by space.
Example: jar cvf TicTacToe.jar TicTacToe.class audio images

Can't create runnable LWJGL jar with JarSplice

I created a runnable JAR with Eclipse for a small SLick2D game. No matter what settings I tried, I always received some sort of error, whether it be UnsatisfiedLinkError, or some class not being found.
I tried JARSplice, but that didn't work either.
Can anyone give me the steps to creating a runnable jar out of an Eclipse project?
The first thing you need is to somehow include the native libraries. You'll find them in the .zip you download from the lwjgl site.
I can recommend using JarSplice to package them. Make sure that when you specify what class it is supposed to run you do not use the default package (This is bad practice anyway). Specify the whole package path (e.g. package1.package2.Main), and it should run.
Use the packaged JAR generated by eclipse as your "input" jar of jarSplice.
If you use your command prompt to try and run your .jar after jarsplicing it, or using the manifest method, or whatever, you would go to the directory your .jar is in and type
java -jar YourGameNameHere.jar
This will give you the errors on why it will not run.

Java application deploy

I have a Swing desktop application and have created a jar file which depends on library (which is kept in ./lib/) and a .txt file in the same folder. Now to execute the jar I have written a .bat file which checks if Java is installed or not. If installed then I run the jar file with command:
javaw -jar TagEdit.jar
Now there are two problems I am facing with this:
I would rather prefer a single executable, if possible.
As using bat file, the console is visible in back (looks kind of weird). Is it possible to turn it off?
Java is everywhere, and there are lots of applications that are built in Java and packaged in a setup, or given as exe. I Googled a lot but could not find a way to create a setup for the software or an exe. How are those software packaged?
Have tried jlaunch, but could not get that to work correctly.
Himz, Eclipse can automatically build a so-called "fat-jar" for you. It is a jar that contains all the dependencies you need.
If you are a happy Maven user, then you have two brilliant alternatives - the shade plugin, and the assembly plugin. They both can produce a "fat-jar" for you. :)
There are various answers to this.
javaws.exe will execute the jar without the console appearing behind
But I feel this isn't really the best way.
I think should investigate using Java Web Start, So you create a JNLP file and have it jar downloaded from the web, I think, you can also have a desktop icon.
If you don't want that
I think you can get/buy binary wrappers for the jar.
You could convert it to an executable. Try Googling java to exe.
Once that is done, you could package it up as an installer using NSIS.

Java: embedding jar inside exe

Here is example to show what i mean: http://www.minecraft.net/download.jsp
If you open the Minecraft.exe with winrar you can see the jar manifest and classes and you can actually launch the jar like this java -jar Minecraft.exe
But when i tried to embed my jar to my own exe as resource (i can see the classes same way as in minecraft.exe with winrar) and launch it with java -jar it fails with message
invalid or corrupt jar file
How can i embed the jar to exe correctly? so it can be launched same way as minecraft.exe?
Use JSmooth. We use it with much success
There is a tool called Jar2Exe. I don't know if it's the same tool that Minecraft uses however.
Launch4j is another tool that supports this (with quite a few extra features such as auto-downloading a JRE if necessary).

How to convert jar files into exe & rpm

I have the following jar files for my app:
DesktopApplication1.jar
Plus , i have used the some extra API's for my app , like jsoup, jexcelapi etc. There are about 7 api's in the lib folder.
How to make a EXE file & RPM file out of all these jar files?
P.S. I am a first timer. So take that into consideration.also, I have used Netbeans 6.8. So the main API is in \dist folder. And the API used is in \dist\lib folder.
thanks in Advance
use jsmooth to make exe from jar
Build your JAR with fatJar to include all the dependencies in it, and then make it executable with your favorite tool (I use Launch4j)
RPM is little bit different, since it is not executable, but package format. There are lots of tutorials, how you build it up.
You could make a BAT file a file with .bat(For windows) extension
Just open notepad and write the following text
java -jar DesktopApplication1.jar
Save the file as filename.bat(the .bat extension is important)
Place the .jar and .bat files together and just double click the .bat file every time you need to run the jar...
If you don't want to keep both together then give the absolute path of the jar in the .bat file
java -jar AbsolutePath/DesktopApplication1.jar
For a linux machine make a file with (.sh) extension rest of the procedure is same...
Try InstallJammer. It provides what you want.
Deploy the app. with Java Web Start. JWS Can make it easy to add other Jars to the apps. run-time class-path, avoiding the common problem with fat jar of violating the API's distribution license (when it says WTE 'you are allowed to distribute this in unaltered form..') and can provide the further benefit of only downloading the parts that the user requires (when the user requires them).
JWS has many other cool features like desktop integration (menu bars, start menu item), splash screens, automatic updates, support by the owners of Java, and compatibility with any platform for which Java is available.
For creating .exe to run on Windows:
Download launch4j from http://launch4j.sourceforge.net.
build wrapper .exe through launch4j.
Download innoSetup from http://www.jrsoftware.org/isdl.php.
Build .exe as installer, the setup file, for user to download and install.
Install rpm for linux:
If your application used other native libraries, you need to download and install Linux native libraries. This is how we build rpm for our app.

Categories

Resources