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.
Related
I'm currently working on a project where I'm using the LWJGL library and I just tried building a .jar out of it all, now the problem is that nothing happens when I try to start the .jar.
My only thought is that maybe the library didn't export correctly but I've been looking around at the other questions here for a while and I've have added everything correctly at the Dependencies tab in the Project Structure, the libraries I need are also in the Artifact Output Layout as extracted directories.
I just tried checking the stacktrace with cmd and it says that it can't find lwjgl in the library path so I'm guessing there's something I don't know about .jar files or something that's causing this error.
Here's the stacktrace:
Also in IntelliJ I've put "-Djava.library.path=lib\native" in VM options, is it possible that this doesn't apply to the .jar or something.
Help is appreciated!
There is a rather complicated process to make an executable jar with LWJGL. You need to use Jarsplice.
Jarsplice has 4 steps which are pretty self explanatory but here they are anyway:
1: Add Jars.
Add the jar you generated as well as all the libraries. That includes lwjgl.jar, and any other jars you used.
2: Add Natives.
Add all the natives you used in your project. These are the files you referenced using -Djava.library.path.
3: Main Class
Select the main class of your program. This could be something like com.example.game.EntryPoint.
4: Create Fat Jar
Click "Create Fat Jar" to create your executable jar!
You can also optionally create a Windows .exe, OSX .app, and Linux .sh executables as well.
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.
I have a project in eclipse. It does everything I want it to do when I click on the green circle play button in the IDE - opens the window, plays the stuff, everything. But, try as I might, I cannot figure out how to get it to do that outside of eclipse.
My project uses the processing.core library to do some of its stuff, but I am unable to get the project to function in the Processing IDE, because of some stupid stuff about one of my classes not being a valid substitute for the type parameter for Collections.sort(List<T>). If anyone knows how I can get it to export from the Processing IDE, that would be excellent.
I need to be able to email/upload to the internet/otherwise transmit some kind of file/folder/webpage that allows the recipient to, without much technical knowledge or work on their part, view a window or something that allows them to view and interact with the program in the same way I am able to interact with the window that Eclipse launches when I press the play button at the top.
I have tried several different ways of accomplishing this, but none of them have worked. I tried exporting a runnable .jar, but it wouldn't let me include the referenced libraries. I tried a regular .jar, but I don't know how to package that up with whatever is needed to be able to view it. I've even tried using the fat jar eclipse plugin for it, too, but I ran afoul of something about being unable to find the main PApplet class for the project.
If anybody knows how to get what I want to happen, or knows of a good tutorial on how to do what I want, I would greatly appreciate any sort of assistance or guidance or anything.
Google has been unhelpful in turning up solutions to this problem, because most of the results I have found were just other people asking the same or a similar question, and then either no answer, or something I had already tried, with no indication of exactly what sort of options or settings I needed to give it in order to accomplish the task.
I am using the processing.core.jar from version 2.0b7, but I don't think that would make a difference, although I plan to try it with different versions if I can't figure out anything else.
A copy of my project folder can be found at https://www.dropbox.com/sh/1n4curhxbgi8fye/A5F6_l7xQu
All the data I have is stuff I've concatenated together from successive versions of the file at http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M1.txt
I've done a quick test on OSX and had to tweak your eclipse project a bit:
You are linking to .jar libraries using absolute path. I recommend using keeping libraries relative to the project
I ran into some memory issues and had to add a couple of compiler flags
Added a main method in Earthquaker.java to initialize as an application.
main looks like this:
public static void main(String[] args) {
PApplet.main(Earthquaker.class.getSimpleName());
}
In eclipse you can export a runnable jar via File > Export > Java > Runnable JAR file. Here are a couple of screenshots:
Personally I prefer using the "Copy required libraries into a sub-folder..." option in case I need to update some dependent .jar independent of the main application .jar.
For reference I've uploaded the modified eclipse project here(Java SDK will need to be changed). The exported runnable jar with a bash script is available here.
And here is the bash script itself which should run on Linux as well:
java -Xms128M -Xmx1024M -jar Processing-DataVisualization.jar
Pretty cool project btw.
Create a simple jar. Create a batch file and specify the class path. Save the batch file. Runnin the batch file will run the app
#ECHO OFF
set CLASSPATH=%CLASSPATH%;myjar1.jar;myjar2.jar;
java mypackage.MyClass
I will try to tell you exactly my problem, because I am stuck for more than 2 days now.
I am trying to make a project in Eclipse from existing source code (a program called sweethome3d) and then modify it. But, the problem even starts from even before modifying the code.
There are the steps that I am following:
File - import - existings projects into workspace.
I select the source code (http://sourceforge.net/projects/sweethome3d/files/SweetHome3D-source/SweetHome3D-3.3-src/SweetHome3D-3.3-src.zip/download)
Then, I try to export it into Runnable jar file
I have also to add some VM arguments in the command line when I try to execute it.
The runnable jar file does not run
in command line
with double click
Do you have any idea what I am doing wrong?
Thanks in advance.
If this is the same as the version of the code you're running, then SweetHome3DBootstrap.java, at line 90, is attempting to load com.eteks.sweethome3d.SweetHome3D dynamically. This class needs the class javax.jnlp.UnavailableServiceException, which is from javaws.jar.
So, when you try to run your JAR, it's missing javaws.jar at runtime. You'll need to either add it to the classpath (specified via the command-line when running, or via the JAR file's 'Class-Path:' manifest header), or re-package the classes from javaws.jar inside the JAR you're creating (like FatJar).
It could be some dependency problem, hard to tell without knowing more. Try using FatJar Eclipse plugin
I am new to Java (and Eclipse) but I have used .NET (and Visual Studio) a fair amount. I also know about compiling C/C++ code and things like that. I know that at the end I get either an EXE or a nice binary file that can be run from the command line.
I have been making a Java utility that uses some external libraries. I need to compile this into an executable that I can run from the command line on a unix machine, but I cannot find any way to do this.
I can build and run/debug in Eclipse, but that is no use to me as this code will be run on a webserver. I just need all the dependancies compiled in to one file but after hours of searching on Google, the best thing I could find was the Fat-JAR plugin for Eclipse and after using that I just get the following error when I try to run the file:
Exception in thread "main" java.lang.NoClassDefFoundError: Network/jar
This is really confusing me and as it is such an essential thing to be able to do I am sure I must be missing something blindingly obvious, but as I said, after hours of searching I have gotten nowhere.
I really appreciate any help you can give me. Thanks.
If you build your java app using Maven (which can be done with every major IDE), then you can use the maven Shade Plugin to build a shaded jar file; this is a jar file with all of its dependencies included.
A shaded jar can be run from the command line like this:
java -jar myjar.jar command line options
You're doing something standard and you're using eclipse. This means, in your case, Maven is your friend. Download and install the M2Eclipse plug-in. Maven is best at managing dependencies. So, creating a jar with dependencies included will be very, very straight forward. There are thousands of examples on the web and in StackOverflow. If you have problems setting it up, comment on this and I can point you in the right direction.
Sounds like your class path on the server needs to be modified to pick up the jar file containing the Network class. How are you executing your program? What path(s) are you putting in the -cp option?
If you are not sure how to find out the contents inside a jar file, run jar tf , this will list the packaged classes. Validate that one of the jars in your CLASSPATH has that class it says missing.
Give us more details and we can help solve it.
I think I should first explain some basics. A Java class can be run as an application if it has a public static void main(String[] args) method. If it has this method, you can run it from command line as:
java my.package.MyClass <attributes>
Before launching your app, you need to make sure that all required .jar files (and the root of your own class folders, if you did not make a jar from your classes) are in the CLASSPATH environment variable.
These are the absolute basics. When you are building a more complex app, or an app for distribution, you'll probably use maven or ant or some other tool that makes your life easier.