What's going on is that I have my images and .wav files in a a project folder and it's running fine in eclipse, however once I export it into a executable jar file it stops loading images. I've tried Extracting libraries into jar file and I've tried packaging them in a jar file. What do I do? I'm panicking because I need to get this ready by tomorrow! I know I have the path right, it's starts the code, but stops after a little.
I get this error:
JAR export finished with warnings. See details for additional information.
Exported with compile warnings:
AdventureQuestv4.0.2/src/adventureQuestv/AdventureQuestMain.java
Here's the code I use to load an image
URL GiantT2 = AdventureQuestBetaMain.class.getResource("GiantT.png");
giantT = ImageIO.read(GiantT2);
I know the images are in the file, it's just that they're not loading.
check out this post.May be you are also having the same issue.
How to export jar with images on Eclipse?
Use fat jar eclipse plugin. Select all resources like .wav and image files etc while exporting.
Before exporting resolve all Java compiler errors and warnings(to the maximum extent).
While exporting the jar file with images in your eclipse ,
You must check these in the Jar Export dialog box,
1.Export generated class files and resources
2.Export Java source file and resources
Options:
Compress the content of the jar file
Add directory entries
please delete the existing workspace and reimport the source code
i hope this may resolve issue
Related
I am working in Java Swing application. I am referring image in my program and it work fine when I run it in Eclipse but when I run it after exporting it doesnt show those files.
My directory hierarchy:
Code 1:
Code 2:
While exporting the jar I have selected
Library handling: Package required libraries into generated jar.
after converting jar to zip, the zip file contains all the resources folders in it.
and also classpath file contains resources folder included.
I have referred many answers here but nothing helped me.
Reffered Questions :
Exported JAR Won't Read Image
Picture inside .jar file wont work when I export it
Exporting Images with JAR in Eclipse (Java)
Eclipse exported Runnable JAR not showing images
Java images not appearing in JAR file
Eclipse exported Runnable JAR not showing images
Try new ImageIcon("/res/images/icon.png") or new ImageIcon("/res/images/icon.png") depending on where you can find the image in the jar file. Because I think without the starting "/" it will try to find it outside the JAR file.
If this is not working then you can try loading the file with [yourclassname].class.getClass().getResourceAsStream(...)
My project's jar file size is getting bigger and bigger as more stuff is added into it. I am wondering if someone has tips on how to generate a smaller jar file.
I export it as a Runnable JAR file and the library handling is Copy required libraries into a sub-folder next to the generated JAR.
In the Properties - Java Compiler - Classfile Generation, everything is unticked.
With these options, I was able to save approx 3MB of space. And I am hoping I can save more by removing the unneeded data.
My .jar file has a .java._trace files in it. How can I remove this from the jar file?
A .xtend and .class file is also there for each class. Since the .class file is just a conversion of the .xtend, I want to remove either one of these from the jar file. How can I achieve this?
I would appreciate any tips and tricks that can help me reduce the size of the jar file.
If you want to exclude the source code file from the generated JAR file of an Xtext based project (and I think any Eclipse plug-in as well), open the plug-in.xml file which is located in the projects root folder. Navigate to the tab "Build" and make sure that your source folders are not selected. Normally there are three source code folders "src", "src-gen" and "xtend-gen". Also the "doc" folder which contains generated java doc is not necessary.
I'm trying to make a .jar file to use in future programs, and in the build path of that file, is another .jar file that is a used resource of the program i'm making.
whenever I try to export with Export>Jar File and hit finish, and open my newly created jar with winrar, there is no other file in there, and i get errors when trying to use it.
I've tried going to properties>java build path>order and export, and selected everything, and it still doesnt work! please help me!
This is in eclipse.
Solved: just used Fat Jar Pluginenter link description here
I have a requirement to dynamically extract the content of a Jar file to a local directory. Remaining part of application will use these content. Everything working well in my eclipse development environment. However following peace of code returns null when it comes into JNLP launch.
InputStream stream = VLCLibManager.class.getClass().getClassLoader().getSystemResourceAsStream("XXX.jar");
I already did following :
Manifest file of JAR that contains VLCLibManager.class updated with proper class-path entries
My XXX.jar is placed under /lib directory of JNLP. It's getting downloaded correctly
Have the entry (jar href="lib/XXX.jar"/>>) in XYZ.jnlp file
Any help appreciated as I'm stucked with this issue for the past few days.
Finally I resolved the issue. Thought of publishing here as it would help others who face similar issue.
I did below :
I packed resources that I wanted as a Zip file and placed into /resources directory of my maven project
Maven compiler plugin packs this zip file along with resultant jar.
So I can load the zip file to my java code using
YourClass.class.getResourceAsStream("/XXXX.zip")
This loads resources to java program. You can unzip as you wanted and use it whereever needed
I want to add DLL's, images, textfiles etc to my project as resources so when I export it, the jar contains the resources so they can be used. I am using eclipse.
Problem is I have no idea how to add it. I've tried adding DLLs/pics to the src folder in the project, but when I export the jar, it is not located there
I've looked at How to make a JAR file that includes DLL files? but it only explains how to extract it, not how to add it to the project and build.
EDIT: I am using an applet to open the jar by the way, sorry for missing it!
Cheers
How are you opening the file in java?
Class.getResourceAsStream(name)?
If you are packaging the code in a jar, then you need to use that command. (as opposed to new File(name), which will get the file in the same directory as your jar)
If the file is not physically in your jar, you can check by changing .jar to .zip and extracting it, then check out this doc http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/javac.html
Usually in an eclipse project, the src folder is the wrong place to put non-sourcecode-content.
You should try moving to maven as your build system, as it is highly customizable and provides you with folders inside your project for exactly that purpose. (src/main/resources)