I have a problem exporting my Eclipse project to an executable jar. I think I do it right but the jar launches than aborts. So I tried with "java -jar nameofproject.jar" and it
says :
Unable to load image :/images/dialogs/server-database.png
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)....
So I decompressed the jar and looked at the directory structure within it and I was surprised to see that my "images" package was included in an unwanted "src" directory, making it impossible for the jvm to find them.
So here is the original project structure in Eclipse:
and here is the directory structure in the unpacked jar :
(the images directory is under the "src" directory which prevents the jvm from finding the pics)
Any idea about how to solve that ?
Related
While execute the jar file. i found this exceptions. But when i tried to double click the .jar file. It shows
if anyone know whats the error. just tell me..
Your jar needs the Jcalendar classes to be executed properly...
is the Jcalendar. jar in the classpath??
For those who Got this error "Java Exception Has Occurred" Try this
I tried the solution in Netbeans. While creating a jar file for swing applications. Your .jar file is placed inside the dist folder. Inside the dist folder you have one lib folder and your .jar folder.
Just select the two lib and jar files and copy and paste in some other new folder. And now you double click your jar file. now your jar file is working fine.
I have a project with the following package set up:
-src
-Interface
-Resources
-images
I want to find the path to the Resources package folder.
By using getClass().getClassLoader().getResource(), I am able to get to the images in the images folder but I also want to get the path for the folder Resources. As I do not know exactly what files will be there it is not possible to look for a determined resource. I am using the JFileChooser to enable the user to select the file, and the aim is to set the default directory to open in the Resources directory.
It works properly when running the project from NetBeans, but when I run the dist executable jar it does not find it as the path returned goes through the jar file. Any idea how to solve this situation?
So... I have been able to find the path returned whenever the project runs in Netbeans and when I run the dist jar. Follows the paths returned:
netbeans: "Scheduler/Resources/"
dist: "Scheduler/Scheduler.jar!/Resources/"
I made a small game in Java.
It had about 5 different classes and the main class being in Game.java
I compiled it into a jar file and I did everything correctly with my manifest.txt which gives the name of the file where the main class is in.
The jar file worked on my computer so I then converted it into an exe file and sent it to someone else.
When My friend tries to run the exe file, it gives him an error saying:
Could not find main class game. Now exiting.
The exe and jar file work fine on my computer but not on a different computer.
We both also run Windows 7.
What went wrong?
I think you need to have every library used in your application beside your EXE file in lib folder. interestingly enough, when lib files are missing, the error shown is about main class, which is so not the case ;) anyway, I had the same problem and got it resolved by including lib folder beside my exe file. this is part of readme.txt generated by net-beans in dist folder, that might be helpful to you:
======================== BUILD OUTPUT DESCRIPTION
when you build an Java application project that has a main class, the
IDE automatically copies all of the JAR files on the projects
classpath to your projects dist/lib folder. The IDE also adds each of
the JAR files to the Class-Path element in the application JAR files
manifest file (MANIFEST.MF).
I created a jar file in my working folder
jar -cfe MRMC.jar MRMC *.class *.jar DB statpack
and I am able to double click the jar file or run it using
java -jar MRMC.jar
But when I copy the jar file to another location, I can no longer run it. I got errors:
Exception in thread "main" java.lang.NullPointerExeption
it seems that the jar file did not find files in the resource folder DB above.
Thank you.
I see two possible reasons:
a) the content of the DB directory does not end up in the jar. Unzip the jar to check what is actually inside. Note: a jar is just a zipfile.
b) you are not referencing the files as a classpath resource, but as a File Resource. Check the methods you are using, if they are based on the classpath or on the file system.
See this question for the different ways to load a file: How should I load files into my Java application?
I am building a java desktop application in Eclipse .
And i need to either export it as a JAR and run through command prompt or export as an Executable JAR.
The project structure is
-- src
-- resources
-- bin
-- build
-- Icon
-- build
And after exporting it , when i try to run the jar file , the icons are not getting loaded in the interface .
Please help me out in this regard .
If you put the images in a resource folder instead of a normal folder, they will export.
Make a new resource folder by rightclicking your project, new, Resource Folder. Add the path you want (like 'src/java/resources') and put the images in there.
(at least, this did it for me.)