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.
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.
I'm facing a problem I have never had before when exporting my eclipse project with external library. I made a little program with spelling correction and I used the language tool library you can find here.
I put this library in the build path and correctly imported into my eclipse project. When I ask to export it into a runnable jar, Eclipse exports only the jar files into languageTool library, but this library contains also some txt and xml files. So when I try to launch the application from command line it gives me error because can't find this txt and xml files. I tried to add to my jar archive manually but obviously it doesn't work. How can I fix it?
Thanks for your time and forgive me for my bad english.
So after all those days I finally finished my work for school, but I need to export it to a jar file. My project includes for example LWJGL. I think he finds it, but I get this Exception:
java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
and so on.
How can I fix this?
When you are exporting your jar file
Tick the check-box of
export generated class files and resources and also
export Java source files and resources
Then, you should have all the source files.
I already solved it. Someone told me to add this line to my source code:
System.setProperty("org.lwjgl.librarypath", new File("native").getAbsolutePath());
and it works after I created the "native" folder in my projects folder.
New problem any way is, that my text is only drawn, if I start my program with command line
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.?
I am trying to create an executable jar file that a user can just click on and execute the code. I have done some research but almost all of the examples are for single files. I currently have all my classes and images being used in my files in a folder. My images exceed the default java memory space and thus I have to run my code with -Xmx500m.
How can I create an executable jar that will go into my folder and run my program from there? Any help will be greatly appreciated!
Just use jar command to create the jar. You may need to link this type of file to Java so that it can be run by clicking on it in Windows. Something like this-
jar cvf test.jar <path to your classes / resources>
I am trying to create an executable jar file that a user can just click on and execute the code
Use Java Web Start to deploy it.
Put all the images and other media in Jar files mentioned in the launch file and they will be downloaded when needed. JWS also has facilities to adjust the memory allocated to an app.
I recommend using https://netbeans.org/ to build your project. Once built it will create the jar for you. You are also able to set compile settings such as the amount of ram you need.
See the following directions https://netbeans.org/kb/docs/java/quickstart.html#build