I need help getting my java program ready for release. I have a program with three packages in each package are classes. Within one package is the class with main that requires all of the other classes when running. My question is how do I build this Java project so anyone can run it. The structure of the files is as follows:
src/table/java files
src/school/java files
src/schoolSort/java files
The main is located in schoolSort/Main.java I have a Windows 7 set up and I have tried:
javac table/*.* school/*.* schoolSort/*.*
And this produced class files but the main file wont run. Help please. I am using Eclipse and have tried that too but it didnt seem to work.
In Eclipse, you can right click on your project and choose to export it as an executable jar. It will ask for your main class (through the run configuration you used) and you should be good to go from there.
Right click on project > Export > Java > Runnable Jar File
You would have to create what is called an executable jar. This is the artifact that you will share with others.
Here is the set of basic steps that you have to follow to create a jar
Here is the set of steps to create an executable jar.
I'm sure eclipse will help you out with these steps, but I have not used it much.
In eclipse, you can do File->Export->Java->Runnable JAR file...
Check your packages are in classpath. If your packages are in classpath, you should try to use 'ant' to build your application.
Related
I have created an application using the JFreeChart library for use on another machine.
Previously I have developed applications with JFreeChart (using the same libraries) which has worked fine on other machines. The only difference is this machine is running Vista.
Please see below for the run-time exception I am getting:
The class that cannot be found, however, is located in the highlighted jar in the below image showing my imported libraries for the JAR. I have also established that this JAR is included in the manifest for the application. See below image:
So I very much need this to work and have no idea where to look next - or what is causing this problem!
Development machine Java version:
1.7.0_45
Target machine Java version:
1.7.0_45
Thanks in advance.
Check the Class-Path attribute in your JAR's manifest, which should contain entries like this:
Class-Path: lib/jfreechart-1.0.17.jar lib/jcommon-1.0.21.jar …
Also, examine dist/README.TXT in your NetBeans project folder, which should say something like this regarding libraries required by your project:
To run the project from the command line, go to the dist folder and
type the following:
java -jar "CISOnlineMonitor.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
This has nothing to do with os i belive.You dont have all the necessery libs within your jar.Try to open a jar and see if you have them in.Fact that you are able to run it on your maschine only proves that.Make executable jar with eclipse or whathever you use.And when it ask you for libs check -Extract required libraries into generated Jar.
if you dont know how to get to that point
File>Export>Java>Runnable Jar File> Runnable JAR File Specification.
Also right click on your project and check Your build path.
RightClick project>Properties>Java Build Path>Libraries
Make sure you have everything correct
EDIT-
As i see you use NetBeans im not sure exactly how to find all this there.Bud it will be very similiar.
I am currently working on a game in Java and tried to export my first release as a runnable jar.
As Eclipse has a tool for this, I tried to use it.
After trying many different ways, I could still not launch the game. I made sure to export as a runnable jar and added the library.
My suspicions are as follows: The game's project is set up like this: src->package->code, Res->images and so on, JRE System Library, and finally referenced libraries->Slick2d, lwjgl, and jinput.
As it happens, I could find no way to get the jar to replicate the workspace folder organization. I believe that is what is causing it to crash; the required files are in unknown paths to the program.
I then tried to reorganize the files myself, only to be told that the jar is corrupted.
If anyone could please help by telling me what the issue may be, how to fix it, or any tips what-so-ever, I would be very thankful!
Use JarSplice to include the library, your jar and the natives in 1 jar.
It didn't work because natives and slick jars were missing.
eclipse comes with the option to package the required Jar along with the main Jar.
I am having trouble exporting my java project from eclipse as a jar executable file. My java project uses an external library (its called jri). I have exported the jri.jar file and set the library path for its native library in eclipse, and it works great in development in eclipse. However, when I export it as an executable jar file I get the following error:
Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in java.library.path.
I have placed a folder called lib in the same directory as my project's jar; this lib folder contains jri's native library. jri's native library is not in one file but in a folder. This is the same setup I have in eclipse.
The way I am exporting my project in eclipse is
Export...
Java > Runnable JAR file
Copy required libraries into a sub folder next to the generated Jar
Finish
And my folder is organized like this
folder project
project.jar
project_lib
jri.jar
jri native library folder
The MANIFEST.MF of my project.jar is:
Manifest-Version: 1.0
Class-Path: . project_lib/jri.jar
Main-Class: index
What I want to achieve is to give another person a folder including project.jar and anything else needed so she/he can run it without needing to install anything else.
Thanks so much
Add a script containing something like that:
#!/bin/bash
java -Djava.library.path=project_lib/native/ -jar project_lib/jri.jar
I export some java projects that way.
This is relatively hard to implement. The solutions I have seen involve extracting the native libraries in the JAR to an OS temp directory and then loading it. I would go for an integrated solution for that. One Jar and Java Class Loader support it, and on the second page you will find links to similar tools.
You can put the libraries inside your jar:
Export...
Java > Runnable JAR file
Package required libraries into generated Jar
Finish
I always export this way.
I don't know if it will work in your case, but worth a try.
Edit:
See these links:
Instalation, setup and setting environment properly
What to do when getting Cannot find JRI native library!
My guess is that this have something to do with LD_LIBRARY_PATH not correctly been set. Or the file wich it is searching for isn't in the path listed.
You know I had the similar problems
Could not extract native JNI library.
all above proposes can't help me. I couldn't stop and start gradle deamon by using follow command:
gradle --stop
I saw that gradle deamon still not stopped in my processes. That's why I kill it in my process and all will be fine :)
Right now i've written a simple SWT application using eclipse, and I want to pack it into an executable .jar file so I can give it out to friends and such. But I have the following problems:
-Right now i'm reading files by using their filename in the program, and putting them in the root folder of the eclipse project. That works fine for running in eclipse, but when I export to jar they're not in the jar. Is there a way to put them in the jar and access them in the code?
-I also need the SWT .jar dependencies or whatever its called(the files you need for SWT).
Does anyone know how to do this?
Take a look at ClassLoader.getResourceAsStream() API.
All you need to do is include these files in the with the source code of your project, then to have access to then have a look at this link
I have created a java application in eclipse, wich needs comm.jar and jexcel.jar and .property files so i have added to libray. I want to make a jar file out of my java appliction, including the external jar files added to the appliction.
How can I do it? To run serialport programs I have copied win32.dll into java_home/bin and comm.jar into java_home/jre/lib and javax.comm.properties into java_home/jre/lib, but when delivering the product it should run only by needing the jre.
How can I solve this? Please help me.
Thanks in advance,
suma
Although your question is not totally clear I suggest using the Fat Jar Plugin should allow you to achieve what you want.
You can use File > Export > Executable Jar which includes all libraries. There is also a checkbox to generate an ant build file as well as the jar in order to customize it further (I for instance make all the paths relative and remove the main-class flag).
You have two "path" issues. The Java Classpath and the path from which dlls are loaded.
If you were using a Java EE app server or OSGi then controlling these paths is addressed by the respective runtimes. Both Java EE and OSGi are likely to be overkill for small projects.
In which case you are delivering:
Your application JAR
The dependent jars
The DLLs
I suggest that on installing your app you place these artefacts into a suitable directory structure, for example .../myapp/lib for the jars and .../myapp/bin for the dlls. Don't copy them into the infrastructure directories, for example the JRE lib and bin, or into Windows32 - that just leads to version nightmares and mysteries when someone installs a new jre.
Having got that structure, how to control the paths? For the classpath, look at the Manifest.mf file. tutorial
For the DLL path, I know of no good alternative to setting OS level environment variables ** before ** launching the JVM. Hence you need a little batch/shell script to launch your app, setting the PATH appropriately.
You can also check maven.
You can right click on the project and say "Export". Now select "Java" in tree of choices. Under that select "Jar File". It'll guide you through the process and will allow you to export you project as a jar file.
Hope thats what you are looking for.
The recently released Eclipse 3.5 has a Export as runnable Jar which allows to put all dependent jars in a subfolder to the jar file, and get the Manifest right.
It is an adaption of the FatJar plugin. Works nicely!