Macosx: How to make a runnable jar file in eclipse? - java

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

Related

Program runs in Eclipse, but exported runnable jar file will not open?

It looks like this is a common problem, but none of the previous posts seem to address my issue.
I believe I've narrowed it down to one problem. Any application that uses an InputStream will not open, but all my other applications run fine.
The application runs fine in Eclipse, but the window won't even open when I try to run the jar file.
Task manager shows it pop up for about a second or two, and then disappears.
I have tried all three options for the Library handling upon exporting and none of them fix the issue.
Can anyone explain this?
Run it from the command line. This will allow you to see the exception that's thrown that's preventing your program from progressing.
java -jar YourJar.jar
I know I'm late, but I want to prevent people having to search hours for the same Error I just did. In Eclipse the path-String isn't case-sensitive. In the exported Runnable Jar File it is. So make sure all the pathsnames have the capital letters in the right positions, or to be save don't have capital letters at all.
Setup Your Manifest
If I had to guess, your manifest doesn't contain your main class OR the classpath is not defined.
Main-Class: https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
Class-Path: https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
If you're using a build tool like maven, it needs to be configured to add these properties: https://maven.apache.org/shared/maven-archiver/examples/classpath.html
Execute Your Jar
There are two ways to run an executable jar. As an executable jar you need to define the Main-Class and Class-Path in your manifest:
java -jar YourJar.jar
You can also skip setting up your manifest and define your classpath and main class through the JVM's parameters.
java -cp=${PATH_TO_JAR} main.package.MainClass

How to test .jar versions?

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.?

exporting a java project to a server using eclipse

I have made a program that parses a text file and then works with the reuslt. I now need to compile this so I can deploy it on a server. 2 things.
1) I want to be able to update the text file regularly...is this possible without recompiling every time?
2) when I compile it with eclipse, I get a jar. If I click it nothing seems to happen. Any advice?
Thanks in advance!
Yes. You can do it without recompiling the program every time.
Create an executable jar from eclipse.
Select your project> File> Export > Java> Runable Jar File.
Please specify the main class where the main method exist.
Now it you click on this jar file , your program will be executed.
Note: If your program does not have any user interface, you will not see anything. When you will click on the jar program will be executed and immediate finished.

Can't create runnable LWJGL jar with JarSplice

I created a runnable JAR with Eclipse for a small SLick2D game. No matter what settings I tried, I always received some sort of error, whether it be UnsatisfiedLinkError, or some class not being found.
I tried JARSplice, but that didn't work either.
Can anyone give me the steps to creating a runnable jar out of an Eclipse project?
The first thing you need is to somehow include the native libraries. You'll find them in the .zip you download from the lwjgl site.
I can recommend using JarSplice to package them. Make sure that when you specify what class it is supposed to run you do not use the default package (This is bad practice anyway). Specify the whole package path (e.g. package1.package2.Main), and it should run.
Use the packaged JAR generated by eclipse as your "input" jar of jarSplice.
If you use your command prompt to try and run your .jar after jarsplicing it, or using the manifest method, or whatever, you would go to the directory your .jar is in and type
java -jar YourGameNameHere.jar
This will give you the errors on why it will not run.

Unable to run JAR file on another PC. Possible issue with Environment Variables?

I've built a JAR file and it executes fine on my PC (XP) which has Eclipse installed. It also works on another PC, which also has Eclipse.
I've tried running it on another PC(XP) that does not have Eclipse. Though it contains the JDK and multiple JRE. The JAR file just does not execute by clicking or from the command prompt.
I am not entirely sure, but my best guess is the Environment Variables are not set properly. Here is the error I receive from the command prompt:
Exception in thread "main" java.lang.NoClassDefFoundError: ...
Any help would be appreciated.
It must be a CLASSPATH issue.
The stacktrace should also say which class it failed to find. Once you have that, then find which jar has that class. Then add that jar file to your classpath or add it to the classpath env variable.
This is likely a classpath issue as others have said.
One thing to note is how your jar is constructed. You have a number of options in the dialog for exporting a runnable jar;
Extract classes into jar
Zip dependencies into the jar - creates jar-in-jar-loader.jar inside the jar.
Place jars in a subdirectory next to the jar.
Depending on what you have chosen for this depends on how the jar will behave. If the classes are extracted, dependent classes not in the JDK should be on the classpath. I'd recommend this course of action as it is simpler.
Now, the question is - are you using a dependency on your classpath not in the build dependencies of the eclipse project? If so, it won't be packed with / zipped into / put next to the jar because eclipse doesn't know about it (but java will still find it on your system because it's on the classpath). Also, if you've saved an ANT script and updated the build path in eclipse, eclipse won't update that ANT script - that is generated once only.
Environment variables are not considered when invoking a jar file when clicking on it (equivalent to running javaw -jar your.jar).
I'm pretty sure that it doesn't work on your first PC outside of Eclipse either.

Categories

Resources