My project runs fine from Eclipse.
But when I tried to make it into a jar file or executable file it doesn't work.
I used the option "Export-Runnable JAR file"
The following message appears just after the eclipse finished the exporting process
JAR export finished with wornings , see details.
the details were ..
Exported with compile warnings:Mario/src/Map.java
and the same for other classes like
Exported with compile warnings:Mario/src/Player.java
and so on.
So that I used the other option "Export - JAR file"
It works fine and nothing appears while exporting it from Eclipse.
But when I try to open the file it gives me
Couldn't find the main class:Frame.Program will exit
Somebody have any idea about what the problem is?
Your MANIFEST.MF file inside the META-INF dir should have a Main-Class attribute pointing to your main class.
The important thing for executable jar is Manifest. Make sure it exists and points to the correct class with main method
Related
I am using the JarSplice tool to create a runnable jar file.
However, as soon as I add lwjgl.jar to my required jar files, it immediately fails to create the jar, saying
"Duplicate entry".
Here is a screenshot of the error: http://gyazo.com/2aac58aa15ba19ff7c61aeda548f43c2
If I remove lwjgl.jar it obviously builds the jar file, but cannot run because I require LWJGL.jar
And here is a screenshot of the added jar files: http://gyazo.com/78a88443336bfb530ed71bd6418e9be1
So, how can I fix this "Duplicate entry" issue so I can create my fat jar file?
Thanks!
I have made use of JDBC in one of my projects and it worked flawlessly in Eclipse. I had to add the ojdbc6.jar to Java Build Path to the project BTW. (I have also not included any Class.forName statements in the code since I heard it's optional for JDBC 4 and above)
When I export the project into a jar file, and try to run it, it complains saying "No driver found for JDBC" and so on. I can see that this is because the ojdbc6.jar is missing from the build path now. Can someone please let me know of a solution?
Thanks!
Here is a simple method to export a JAR that uses external jar as libs:
You have to write a manifest file, I named it jar.manifest.
The content in manifest file looks like:
Manifest-Version:1.0
Main-Class:com.enginebai.activity.MyJDBCProgram
Class-Path:lib/ojdbc6.jar lib/some-externam-lib.jar
and make sure to put a blank line under Class-Path, otherwise the JAR won't run. (I have no idea why to put a blank line over there.)
Let's go back to eclipse:
In eclipse, you export your classes and remember to select above manifest file.
Make sure your ojdbc6.jar be in project/lib folder.
Open your terminal and cd to project root directory, enter `java -jar your-jar-name.jar', it should work then.
put ojdbc6.jar on classpath when you run your jar
I have done some research and found a solution that seems to work.
I have exported the project into a "Runnable Jar file" instead of just a "jar file".
This way, I was actually able to repack Jar files from my Build Path into the new Jar file I am exporting my project to. Simple and clean.
You also might want to look at signed Jar files and any other certificates in your existing jar files in the Build Path. They cannot directly be repacked through the export option.
I have exported a jar file that I want to run the console. The code compiles and runs correctly in eclipse but I am having an issue running it from the console.
To me it looks like the referenced jar's I added via built path in the Eclipse project file and not being added to the export. If that is the case, how do I ensure that they do? If not, what am I doing wrong?
When you export your source code's class files to a jar using eclipse, only the .class files of your source are exported! Hence your exported jar file doesn't contain the referenced jars you mentioned in eclipse! Due to this, the error occurs while executing from command prompt.
Solution:
Take all the jar files required to execute the program, store it in the same directory as you store the exported jar file. Now while executing the java command, provide all the jar file's names in classpath field as following:
java -classpath .;JAR1.jar;JAR2.jar MainClass
Once you do this, your problem should be resolved!
The dependencies need to be on the classpath, i.e. run like this:
java -cp <path_to_jar1>;<path_to_jar2> -jar ScrumTimeCaptureMaintenence.jar
When running from the command line make sure any dependencies are set on the class path by listing them in the -classpath parameter
So I have a small Java program with some gui that I have runnning in eclipse just fine. I followed the fatjar tutorial to create the .jar, but when I try to run the .jar the first gui window appears but none of the functions work. When I ran it in cp, clicking the button generated an exception basically saying some of the object types could not be resolved as type, all of which were from import libraries. Has anyone seen this before, I tried using this program jarfix for an issue similar to mine, but nothing.
Please define
When I ran it in cp
The format of the java command should look something like
java -cp /path/to/jars com.main.class
You could start locating the source of the problem by opening the jar file with an archive program (e.g. winzip) and look if the class / type is included in the jar file or not.
If it is there it might be a classpath issue. If it is not there something is wrong with building the jar file. Musn't the included jar file be set in the "Order and Export" tab in the java buildpath dialog?
I am not aware of fatjar. But I faced similar problem, might be somewhere it is linked to your issue.
In my case everything was working when I was running through eclipse, but when I created JAR using Eclipse I faced issue as what you are facing, but in my case it was issue of accessing resources inside JAR File.
So solution was,
Right Click -> Export as -> Jar, here check the box "Add Directory Entries" and then create the JAR. Ans all worked.
Above all, first you should check whether the jar which is generate is correct or not by just open it with winrar or similar tool and see all classes and resources are placed properly.
An alternative would to place all those jar files in the same folder. i.e. if your application jar file is App.jar and other dependencies are A.jar and B.jar. Then drop A.jar and B.jar in the same folder as App.jar.
If you double click on App.jar it will by taking the other dependencies in the same folder by default.
I write a very simple java program with two classes: Business and Main.
I want to create a jar such that if I email it to someone they can:
run the program (i.e. run the jar)
open the jar to view the source code.
the code can run on mac or windows
I have been using IDEs for so long I have forgotten how to do this.
I am using netbeans 7.x
EDIT:
I found the following way on Netbeans:
properties > packaging > exclude from jar file :: delete **/*.java
But when I try to execute the jar using
java -jar mybusiness.jar
it says
no main manifest attribute, in mybusiness.jar
But note that my jar has a main class. Am I missing a manifest file?
You can export a JAR file that includes the source code using Netbeans:
Right click on the project and select properties
Build -> Packaging
Remove Java files from the excluded files. And select build jar after compiling
It will create the jar file that includes the source code if it successfully compiles.
Well surely an IDE can do this too?. Just make some text files and put the source into them and drag them into the ide's. It's java so it should automatically run on all platforms. I am not sure what the problem is here?
This link explains how do u create manifest file and how do you specify your main class in manifest file as its necessary for executing jar.