I have a project in eclipse which uses part of another java project for changing some variables. I need to create an executable file from my project but all instructions that I try doesn't work.
I created a runnable jar file by exporting my project but the jar file doesn't run. Then I used the launch4j to create an ".exe" file from the jar file but when I click one the .exe file instead of running, it unzips to a folder.
just in case if it is an important point, I am using mac os.
In Eclipse;
Click Next and give a destination
Related
I have a project with 3 java files:
Title_Screen .java
Game_Screen .java
Game_Code .java
Game_Screen and Game_Code use OpenGL, and Title_Screen opens Game_Code which opens Game_Screen. In eclipse, the program works perfectly, but when I try to export it as a runnable jar file, no matter what I do, it always just exports Title_Screen.java. What am I doing wrong, and what steps do I have to take to export all three java files in one .jar file?
Edit: It seems to only happen to my program, perhaps it's something to do with the OpenGL libraries?
Edit 2: I removed the libraries from my program, same results as exporting it to a jar file. My actual problem is that I can't put in the libraries.
Edit 3: Problem resolved! All I had to do was use jarsplice to create my runnable jar, not Eclipse. Tutorial I used: https://www.youtube.com/watch?v=YqGUk84BmlQ
You can use the following command to build the jar and specify the main class entry point (Main).
jar cfe output.jar Main src/Repository/* src/util/*.class
you can write multiple files when creating the jar
jar cf Output.jar src/util/Main.class src/util/SubMain.class src/Repository/*
Or from eclipse
Put all your files in a folder in your Eclipse project and then:
1.Right click in your folder
2.Export
3.Java -> Runnable JAR File
What steps are you following to export it as runnable jar?
Are you able to run the jar file successfully?
Steps to export Runnable jar is :
Right click on project and select "Export" option.
Provide the destination path where the jar file needs to be store.
Export
I want to run my java project which i've built using Eclipse IDE. Now my goal is to create a batch file which will execute my project with one click. i referred question , but didn't get any idea. Please give me a solution. Thanks in advance.
Because you are working in eclipse, this makes things easier. First, export the whole program as a executable jar. You can do this by going to Files>Export and then in the pop up go to Java>Runnable Jar. Then follow the steps required to make it. Next you make a .bat file and write the following code.
start javaw -jar NameOfJar.jar
Make sure that you put the file in the same directory as your jar. Now you should be able and click on the .bat and execute the program!
1.Open Notepad & write
#echo off
javac YOUR_JAVA_FILENAME.java
java YOUR_JAVA_FILENAME
2.Save-As executeJavaProgram.bat
Make sure that YOUR_JAVA_FILENAME.java resides with your batch file and java path is set in environment variable.
3 . Double click on batch file.
Follow this tutorial to create a jar file of your eclipse project.
After doing it create a batch file in the same folder where you exported the jar with the command: java -jar yourjar.jar
Create jar file using eclipse i.e right click on your project select export jar file then provide file name to store your jar file. In this file eclipse will keep all .class file only and in META-INF folder main class definition if your are creating executable jar file.
It export it fine as a Jar, but when I double click the project it won't load up.
I'm building a Java Slick2d game (my first). I've tried on both windows 7, and Ubuntu 12.10. Any suggestions?
If you run the exported jar file from the terminal, you'll see an Unsatisfied Link Error. To resolve this, you need to include the LWJGL natives. If you want everything in a self-contained jar, the easiest way is by using JarSplice.
Let's walk through how to do this step-by-step.
Open up JarSplice
Add the jar you exported from Eclipse.
Add the LWJGL natives. These can be downloaded from http://www.lwjgl.org/download.php. I'll be exporting for Linux, so I'm going to include the Linux native files. The native files should be in a folder called native.
Now specify the main class in your project. Don't forget to include the class's package.
Click Create Fat Jar and you're done! You can also export to a Linux .sh, Mac .app, or Windows .exe. Just make sure you include the appropriate natives.
Have fun sharing your game with others!
make sure you mention the Main Class: in META-INF
Detailed instructions
The detailed instructions for creating an executable JAR file for a stand-alone SWT file are listed below.
Create a runtime folder for the desired runtime target on your system (e.g., c:\swt\runtime-linux). Note that the target platform does not need to be the same as your development platform.
Find the correct SWT JAR file for the desired target platform. You can download the desired ZIP file from the SWT website. For example, for Eclipse 3.3 and a target platform of Linux, download the file swt-3.3.1.1-gtk-linux-x86.zip. Expand this ZIP file and copy the swt.jar file to the runtime folder. Remember that this swt.jar file is specific to one platform, in this case Linux.
3.Create a manifest file for your application using the Eclipse text editor (e.g., myapplication-manifest.txt). The text of the manifest should be as follows:
Manifest-Version: 1.0
Class-Path: swt.jar
Main-Class: mypackage.MyClassWithMainMethod
(blank line at end of file)
4.Make sure the manifest file ends with a blank line. Put the name of your package and class that contains the main() method for the Main-Class.
In Eclipse, select File/Export/Java/Jar file and press Next.
On the JAR File Specification dialog, select the source files for the classes you want in the application. In the export destination, browse to the runtime folder and enter in the desired name of the JAR file (e.g., myapplication.jar or myapplication_linux.jar). Press Next.
On the JAR Packaging Options dialog, make sure the "Export class files with compile warnings" box is checked. Otherwise, if your source files have any compile warnings, they will not be included in the JAR file. Press Next.
In the JAR Export dialog, select the option "Use existing manifest from workspace". Browse to the manifest file you created above. Press Finish.
If the JAR file already exists, you will be asked to overwrite it. Select Yes. If your project had any compile warnings, a message will display. If so, press OK.
At this point, the JAR file for your application has been created in the runtime directory.
If needed (i.e., your target platform is different than your development platform), copy the runtime directory to a directory on your target platform.
In your operating system's file explorer, browse to the runtime directory and run your JAR file. For example, in Windows, you can just double-click on it in the Windows File Explorer or, from the "cmd" prompt, you can enter the command: java -jar myapplication.jar. The application should run.
Find file "MANIFEST" in the jar file, and add line :
"Main-Class: {Your executable class name (the class with main method)}"
I have a Java desktop app with gui.My app is using some xml files from the "export" folder. When I export the app into a runnable jar file, the app is not working properly, because the jar does not contain this xml files, or the path to the files is wrong.
Is there any possibility to export a Java app into an executable jar file from eclipse and to tell somehow to include an additional folder, with the same structure?
More information
My project is using some xml files, organized in the following hierarchy:
templates -> HASH CODE fgrtsgdtagsdnjf -> test -> document.xml
templates -> HASH CODE sgdtfhfnjnjcnjc -> test -> document.xml
When I export my project into an executable jar file I don't know how to specify to my app to use that files. I have FileNotFoundException.
So far, I succeed during export into an executable jar file to export that folders with XML files as well. So the files exists in the jar archive. but I do not how to indicate to use them in my project?
Since you said you get FileNotFoundException, I assume you are trying to use File, FileStream, FileReader or similar; you can't use those, you need to use class.getResourceAsStream() (search first in the the same directory as the class) or class.getClassLoader().getResourceAsStream() or getSystemResourceAsStream().
Eclipse packages the contents of the source folders (i.e. src, export and test) in the root of the JAR, so if you have "export/document.xml" you'd use 'MyClass.class.getResourceAsStream("document.xml")'. And remember to close the stream.
My app is using some xml files from the "export" folder.
If export folder has only required xml files, then just move it inside src folder. It would be automatically included once you Export as Executable Jar
Another option is to right click the folder and select Build Path, experimenting with it might help.
Is there any possibility to export a java app into an executable jar file from eclipse and to tell somehow to include an additional folder, with the same structure?
When you export as executable jar there is an option to save scenario as Ant script. Later you can modify it and Run as -> Ant
I've made a program to help me out with some stuff, but every time I need it, I open Eclipse and Run it.
Is it possible to create an executable file so I won't need to open Eclipse every time?
The commands I use is basically System.out.println() and Scanner to read what I type.
Right-click on project.
Export as runnable jar.
File -> Export -> Java -> Runnable JAR File
You'll have to choose the main class that you want it to run. This will allow you to double-click on the JAR, and have it run that main.
You can File > Export > JAR file to export your project as a jar and put the java command to run the jar on a windows batch file. Alternatively you can File > Export > Runnable JAR file
You can either create an executable jar file (using eclipse, or a build tool like "ant" or "maven") or you can also create a "real" Windows-executable file (which you can also give to customers/friends).
I am using JSmooth a lot ( http://jsmooth.sourceforge.net/ ) - this builds a wrapper around your jar-files and can help the user with downloading and installing an appropriate java virtual machine version.
Probably the executable jar (see answer of Serplat) file is what you need :)