I had a question regarding JDeveloper's methodology for generating executable jar files.
I have tried several tutorials for building JAR files and finally found one that generates an executable jar file that i can run on a Linux system. Here is a link to it http://idlebrains.org/tutorials/java-tutorials/generating-executable-jar-file-third-party-library/
However, the building of the 5 MB file takes, on average, 1 hour and 40 min. I looked at the JAR file once it was built and it seems that all the libraries that i had included in my build were somehow decomposed into their component code. What I mean is that the libraries that i included in my build don't appear as .JAR files inside the executable JAR.
I have been looking into why it would take so long and why JDeveloper would not simply add the dependent JAR files in the executable JAR as simply JAR files. However I have not had much luck.
Any insight would be greatly appreciated.
Eclipse can build jar files which you can then execute.
Right click on project -> export -> Java -> Runnable Jar File -> Select the Launch Configuration Corresponding to your Project -> Package Required Libraries in Generated JAR -> Select Export Destination -> Finish.
It should only take a couple minutes, tops.
Then, go to the JAR file, right click on it -> properties -> permissions -> allow executing file as program.
Now you should be able to run the JAR file by opening it with Java. If you wish to see console logs, open up the terminal and run "Java -jar location/to/jar/file.jar". Note that this method doesn't even require for the JAR file to be marked as executable.
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 am using Inno 5 Setup Installer in Netbeans to build my Java Swing application into an executable set up file. It creates an app.exe setup file with all the lib(all jar file) and app.jar.
So once user executes app.exe file, it create a folder at C:\users\username\local\appname which has the app.jar file and the libraries.
Is it possible to add additional text files in app.exe setup? so these text files will also be avaliable in "appname" folder when executed. These are required for the app to run.
Thanks for your time :)
In Inno Setup there is a ScriptWizard which i recommend to use. After a few steps there comes this window:
NOTE: I use the application from Inno Setup. I got the Screenshot from there.
If you click on "Add files" you now can select your text file and it will be setup within your path.
If you don't want to use the wizard, you can add your additional files as entries in the [Files] section, like for instance:
[Files]
Source: "C:\path\to\your\text\file\you\want\to\add\to"; DestDir: "{app}"
Except listing one entry per file, you can add e.g. all files of a certain extension from a given directory.
When you right click your project in NetBeans then Package as -> Exe installer, then NetBeans does several things:
bundels your app in an exe and adds JRE files
creates an Inno script for you
executes the inno script and create the installer
This is nice but, if you need to change stuff like add more files, app name, vendor, version, install location, icons, etc... you need to edit the .iss file. But...where is that .iss file NetBeans creates?? -> check below for answer
The cleanest way to have an installer, and a native executable for your Java app developed in NetBeans is the following:
check the instructions here, to enable native packaging https://netbeans.org/kb/docs/java/native_pkg.html
Build your app
Right click on NetBeans project -> Package as->Exe installer. This step is to obtain the .iss setup file produced by NetBeans. You can use it as starting point.
The .iss file is generated at C:\Users\YOUR_USER_NAME\AppData\Local\Temp\fxbundler[somenumbers]\images\win-exe.image\YOUR_PROJECT_NAME.iss
build and clean the project again
Right click on NetBeans project -> Package as-> Image only. This will wrap your app in an .exe and will add JRE files needed to run the app.
The exe and dependencies will be generated in dist\bundles
Add more files in the app folder based on your needs
take the above YOUR_PROJECT_NAME.iss script, along with your files from dist\bundles, adapt YOUR_PROJECT_NAME.iss script based on your needs and generate your installer for your java wrapped in a native executable.
Good luck!
I have this code, in where I have 'jar' file that I use as a library. And in my "src" I have multiple packages with ".java" files in them.
I am highly confused about how to compile and run this program on terminal.
I have attached an image of the directory.
Link: https://www.dropbox.com/s/yfg22v9y78yndan/DirecotryPic.png
Thanks in advance :)
Why do you have a jar file in the src folder??
You should be referencing them from Java build path. Right click on your project -> Java Build Path -> Configure Build Path -> Libraries.
Add your library files here. Not in the src.
From the picture it seems you are using eclipse IDE. Eclipse builds the file automatically. From the Menu bar click Project and make sure you checked Build Automatically.
To run this on the terminal, export this whole project as Runnable Jar and from terminal execute this "java -jar yourproject.jar"
Right click on project -> Export -> Runnable Jar.
Is it what you are looking for???
First of all: JAR files should not be copied to the src folder. As far as I can see DirectoryServer.jar is in it right now.
Secondly: .sh files should be moved to the root of your project too.
You could easily generate Ant buildfiles with Eclipse (Export.. > Ant buildfiles) and then use them from terminal (installing ANT is a must!).
Other option would be to export a runnable JAR directly from Eclipse, then run it from terminal.
I hope it helps! Feel free to ask in comment if you have any more questions!
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 :)