After exporting a game app I'm making as a runnable .jar file, I ran it from the command prompt only to find some issues. I've had to solve some issues with not finding audio path and not being able to read/write into .txt files. Audio I've looked and was able to solve, the files one I looked and came to close to solving it but after making a post here I learned all I was missing was a . at the start of my fileNames. Now there's only one problem left.
When I export it with:
extract required libraries into JAR
it gives me this exception:
Catched FileNotFoundException .... -natives-windows-i586.jar(System couldnt locate especified file) ...
Exception in thread "main" java.lang.UnsatisfiedlinkError: Cant load library: ...\gluegen-rt.dll
When I export it with:
package required libraries into generated JAR`
it says:
Catched MalformedURLException: Could not open Inputstream for URL: 'rsrc:glugen-rt-natives-windows-i586.jar', ....
Exception in thread "main" java.lang.reflect.invocationTargetException
Caused by: java.lang.UnsatisfiedlinkError: Cant load library: ...\gluegen-rt.dll
The build path looks something like this:
Source: CubeSurvivor/src
Projects: JOGL (where glugen-rt.dll is and this project is required because it contains everything related to graphics)
Libraries: JRE System Library[JavaSE-1.8]
Order and Export:
CubeSurvivor/src with box filled
JRE System Library[JavaSE-1.8] box not filled (tried with box selected)
JOGL box not filled (tried with box selected)
I dont understand what I'm doing wrong, from the looks of it, it seems maybe the project containing JOGL isn't going to the .jar file but I've confirmed that it is while opening with 7-zip but I couldn't find gluegen-rt.dll (maybe haven't looked well enough its thousands upon thousands of files). That file along with other .jar files are located inside a folder on JOGL.
Maybe this file isn't being copied or extracted to the .jar file created?
Or is there something wrong with my build path? If so, what should I do?
Should I add all the files inside JOGL to the src?
Edit:
I extracted the jar file with 7-zip to run a file search, I made random searches(after all its thousands of files) and all except those in a folder called lib, JOGL.iml and referenced libraries, all inside JOGL, were not found, the folder itself was not found. Everything else was.
Heres what the inside of JOGL looks like:
JOGL Project View
lib, JOGL.iml and referenced libraries are not in the jar file aparently.
Ok so this thread has been resolved, the answers are in the comments, so if anyone encounters a similar issue be sure to check it. I dont know how to make this thread end, im sure a moderator will see it.
So, i just wanted to say thank you all for your precious help and sorry after all it was my mistake not using JOGL properly. This link might help others in the future so im posting it here.
http://jogamp.org/wiki/index.php/JogAmp_JAR_File_Handling#Eclipse
Related
I've found a bunch of Stack Overflow Questions and Answers, but so far I haven't found any that work for me. I am trying to make an executable jar in Eclipse from a program which requires an extra jar and a dll. The way I got this to work properly in Eclipse is by configuring the Build Path as shown in
this image. The hierarchy of the project is this. I've tried messing with the Manifest file a bit, but I haven't made any progress with that.
I've been running the jar by using java -jar /path/to/jar and I keep getting an error saying Exception in thread "main" java.lang.NoClassDefFoundError: com/jacob/activeX/ActiveXComponent .... I've tried defining a path to the jar using -Djava.library.path=/path/to/jar and I get an error saying Error: Could not find or loaded main class outlook_dl_2.jar.
Is there any way to solve this without using a third-party application like One JAR? That's the only thing I can find that I haven't tried and I'm trying to avoid it if possible, since I feel like it really shouldn't be necessary. I'll use it as a worst-case scenario, but I would like to get this working without it.
Anyone know what I'm doing wrong here?
I've run .jar files before, but I've encountered a "different" situation, and I'm not sure what to do. I'd appreciate if someone could help me out.
Previously, I programmed with Java 6 and Eclipse Juno exported all my programs to runnable jar files. I'd get a .jar file that I could run by just double clicking on it. The files always looked something like this (note the jar file icon):
Recently, I wrote a program in Java 8 with Eclipse Luna (Release 4.4.0) and exported it to a runnable jar file, and I got something different (note the different file icon):
It no longer runs when I double click it. Instead, my computer uncompresses the jar, as it would a zip file. I tried running it from terminal. I cd'd to the directory and typed
java -jar graph3D.jar
I got the following error message:
Error: Unable to access jarfile graph3D.jar
After uncompressing the jar file, I found a folder named META-INF with the manifest file, MANIFEST.MF in it. It was the only file that seemed to resemble an executable file. Do I have to do something with that?
Could someone explain how I can run the second jar file graph3D.jar? Is it something new with Java 8, or something different about Eclipse Luna, or something else?
(Both programs run fine in Eclipse, by the way)
Thanks for your time and help.
Edit:
Below was the dialog box Eclipse displayed if anyone is interested.
Selecting "Use .jar;.zip" makes the filename "graph3D.jar;.jar;*.zip" .
Selecting "Use .zip" makes the filename "graph3D.jar;*.zip"
Selecting "Cancel" doesn't let you go forward.
You'd have to manually delete the extra file extension.
Somehow when you exported the file, the filters for the file dialog box (*.jar;*.zip) got attached to the filename, which is graph3D.jar;*.jar;*.zip, not graph3D.jar. Java can't find it because it doesn't have the name you supplied. Rename the file and pay close attention next time you export; either you fat-fingered something, or you're triggering a significant bug that needs fixing.
I recommend that you will access the build folder after you've built your project on the IDE under your project folder (in your workspace) and copy both the libraries folder and the .jar and post them wherever you want the program to be "installed", you'll then have an executable jar that should run smoothly without problems, just as I said don't forget the lib folder.
I think there is nothing new in Java 8 related with the running jar, I guess you need to check the the Eclipse export issues, it seems your classes are missing from your second jar file.
This is a really common error, because there are tons of threads about it, but I'm not sure if since my situation is slightly different from all of them the solutions don't work?
Basically, I'm in eclipse. I have a source folder called src, then I have a package that goes down three folders, then the class in question. The class uses the code:
BufferedImage im = ImageIO.read(Thread.currentThread().getContextClassLoader().getResourceAsStream(filenames[x].concat(extension)));
surrounded by a try/catch. filenames is an array of all the file names I am loading (this code is run multiple times in a for loop) and extension is ".PNG". The pictures are located in another source folder called EngineTextures.
Running this program works fine in Eclipse! All textures are loaded and all my other code runs! However, I export it as a runnable jar and run it in command prompt to recieve input == null errors on all of them, pointing to the line that has ImageIO.read(Thread.currentThread() in it.
The kicker is this whole thing worked in a separate project before, and when I even tried re-exporting that project, I recieve the same errors on completely unchanged code. This leads me to believe I have some obscure Eclipse setting changed wrongly.
Opening the jar, my MANIFEST.MF has a version of 1.0 and a classpath of just plain ., which I thought was correct for this kind of thing? The Main-Class points to the right place, and all my pictures are right there next to the META-INF folder.
Solutions I've looked at unsuccessfully:
getResourceAsStream working in eclipse, but not when run as applet in browser
Why does getResourceAsStream() work in the IDE but not the JAR?
Java IDE - Eclipse, Importing resources
Audio file in jar made by Eclipse IDE
getResourceAsStream() returning null in jar but fine in eclipse
Additionally, I completely deleted the workspace and recopied my pictures and code into the same state, thinking maybe some .metadata thing was wrong, to no avail.
Thank you, in advance, for any and all help. I hate to make a repeat like this but no solutions have worked thus far. Please let me know if I have not given any crucial information.
Opening the jar, my MANIFEST.MF has a version of 1.0 and a classpath of just plain ., which I thought was correct for this kind of thing?
No. The Class-Path entry in a JAR file names other JAR files, relative to the location of this jar file. It doesn't name directories:
"The value of this attribute specifies the relative URLs of the extensions or libraries that this application or extension needs."
That in turn implies that resources to be loaded via getResourceAsStream() must be in JAR files.
I'm doing the Ludum Dare 25, using Java Libgdx trying to export my jar.
It was working absolutely fine earlier, I exported and could run it fine. Now when I export it the exact same way, it crashes as soon as I open it. Running via CMD I get the error
'Could not find or load main class'
I've opened it up in winrar and checked the Main class is there and the manifest points to the correct place. I don't understand what's wrong.
All help appreciated, many thanks!
Solution Found
Odd issue, despite the error message had nothing to do with the class, the jar exporter made one of my image files lowercase or something, so that it was messing up it's references
How to export to runnable java file with eclipse using slick and lwjgl (Light Weight Java Graphics Library)?
So, I have done some research into this and believe I have found the root of the problem and what needs fixing, now I need to figure out how to fix it.
I have a fairly large project that use slick and lwjgl. These are both provided as .jar files that I have added to the java build path in my IDE (Eclipse INDIGO, in case you where wondering).
My goal is to export the piece into a single runnable jar file. Eclipse gives me three options for this:
Extract required libraries into generated JAR
Package required libraries into generated JAR
Copy required into a sub-folder next to the generated JAR
I have been gunning for the second options and it seems the easiest to deal with logically. Anyway when I select this option I press the FINISH option (the only one available to me other than BACK and CANCEL) I get the generation progress popping up for a sec and all seem well. However, if I run the resulting file I get an Unresolved Linker Error as it cannot find lwjgl.
Seeing as both slick.jar and lwgjl.jar are inside the generated JAR when viewed with winRar, I assume that some information is being lost about the java build path when everything goes from the IDE to the runnable JAR.
My research so far seems to suggest I can point the generated JAR to the enclosed files it needs through something in the manifest.txt file but this is were I have been unable to find anything more concrete.
Can anyone please advise me where to go from here?
P.S: I have tried almost every permutation of the export option and environmental options for the build path but when I run the generated JAR it get various differing errors that still all mean "I cannot find this here external".
P.P.S: I forgot to add, eclipse itself is mentioned in the manifest file as follows:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ lwjgl.jar slick.jar
Class-Path: . lwjgl.jar slick.jar
Rsrc-Main-Class: Game.Game
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
Every bit of common sense tells me that needs to be changed as it refers to the .jars' location but again, not sure what to or where to begin.
You could use JarSplice, just export the jar from Eclipse, with your classes and resources (don't include any libraries at this point), then use JarSplice to add any libraries and natives (like lwjgl and slick) and make the jar runnable.