I have a project I'm working on and planning to export as a .jar to be released to public. However a major problem I have with Java is that some things work in Eclipse, but won't as a .jar file (ie directory problems: sometimes the directory is right in Eclipse, but when exported it will no longer work). I would like to know if there is a way to check for errors in a jar file directly in Eclipse. I know you can import the new jar file as an external jar file and run it that way but I don't like having to reimport a new jar file every single time a create a new version of one. What can I do?
You can write logs in your code and see that logs in java console when your jar start executing.
how exactly you are building jar ? using command or anything else.?
Related
So my old jar has the libraries exported into it as folders containing the .class files. And my new jar has each library .jar packaged into my jar in a libs folder like my workspace. I need it to export with the former setup. Pictures below explain my issue further.
The reason the packaging changed is because I reinstalled my OS and I don't remember how I had done it before since it's been a while since I last exported a jar for this project, I think what I did last time to get around this issue was I used IntelliJ Idea to export it but I'd much prefer figure this out with Eclipse. There seems to be a setting that does exactly what I want under the Runnable Jar Export wizard but I'm not exporting a runnable jar as it doesn't have a Main method.
old jar picture:
new jar picture:
new jar picture 2:
Yes, a fat JAR can be created via the Runnable JAR file, but not via the JAR file export wizard.
So either
create a dummy main method or
use Ant, Maven, Gradle or something else
to create a fat JAR.
Make sure that you put everything in the source folder that you want to copy to the output folder and include in the JAR.
Switching to IntelliJ Idea allowed me to export in this manner out of the box with default settings. If anyone knows how to get this function in Eclipse feel free to add it.
Edit: as per #howlger's comments I've found a solution where Eclipse works perfectly for my use case.
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.
To be clear, i know there is a thread like this on stackoverflow and he uses eclipse while I use Intellij. Creating an executable jar in eclipse and intellij are different. So before downvote kindly consider my scenario. I created a simple java game using libgdx and want to export it in an executable jar. But before doing so, I experimented in creating a jar of the one in the tutorial video of official LIBGDX.This is the jar file Dload it here.. If you execute it opens then close again. But when i ran the project in intellij it runs without error.
This is the image i was expecting if i execute the jar file i created..
What is wrong when i tried to create a jar file?? Anyone?? Thanks
Just open your exported jar file like a zip archive and export your assets folder and libraries beside your jar file then test it again. Hope this helps.
Used eclipse in the past fro java coding and didn't have many issues but decided to give netbeans a blast
I'm trying to create a jar file with all dependencies as one jar and yes am familiar with the java-web-start-option and also the jar actually exists in my dist folder once built.
Problem 1
All's good and well, I can launch the jar but seems not without its lib folder which contains: AbsoluteLayout.jar + beanbindings.jars. Something I will need to figure out as I go along.
I call a few batch scripts to complete differenet jobs for me in the java program e.g. one finds memory amounts and displays in a JTextArea. When I use the program within the netbeans ide all works fine.
Problem 2
When I launch the jar file thats in the dist folder it launches just fine but cannot find the batch/bash scripts at all. Below is the path I use within the program which as I mentioned works fine in the IDE and just wondering why it cant find the same path in the jar.
I assumed when I created and built like in eclipe it would make all these commands work in the existing jar in my dist folder (bin in eclipse ofc)?
String[] filepath = {"cmd.exe", "/C", "..\\Enterprise\\src\\enterprise\\batch\\memory.bat"}
Any suggestions, thanks in advance!
Just try to change your path. Just make a flag if it's in your ide then select this path, if not then use another path.
Try this link to get the application path in java.
Get the application's path
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