Exporting a java file as a runnable .jar [duplicate] - java

This question already has answers here:
Eclipse exported Runnable JAR not showing images
(8 answers)
Closed 7 years ago.
I'm trying to export my java file as a runnable .jar file using Eclipse. The procedure I'm doing is:
File > Export > Java > Runnable .jar, and my options are as follows:
http://gyazo.com/88ad22e9382e964e47a1a21200ff0f4b
My problem is, when I run the file in Eclipse, any imported pictures (e.g. a logo for the GUI application) shows up, but it doesn't show up in the exported .jar file.
I.e:
http://gyazo.com/4092e8756f4054ce00429d50c33c22af - in Eclipse
http://gyazo.com/7309d84f64832b22560ef023c9349a52 - running the .jar file
My images are in a folder called filesrc which is in the same folder as my project, as can be shown here:
http://gyazo.com/20f8191ee173e06638811c237f985c6f
What am I doing wrong? How can I make these images appear in the .jar?
Thanks

Make sure your exported .jar file contains the folder with your images. So lets assume that your images are in a folder called \images at the root of your JAR file.
In your code, you need to change the way your are getting these images to :
Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/plus.png"));

Related

How to Compile .java files into .jar file? [duplicate]

This question already has answers here:
How do I make a JAR from a .java file?
(8 answers)
Closed 6 years ago.
I just have some (134) .java source files with me and I'm pretty sure that contains all the necessary code!
I want some quick tutorial to compile this program into a .jar file.
(I'm on a windows platform btw)
I have tried javac and jar commands. I got my .jar file but it's not opening!!!
Thanks in advance!
Best practice is to make use of Ant/Maven/Gradle kind of build program tools that can take care of creating Jar files.
Other way is to just make use of Eclipse's feature for exporting the project as a light weight Jar file or Runnable Jar file(which includes dependencies).
Place all the files you want to include in the JAR file inside a
single folder.
Open the command prompt in Admin Mode
Navigate to the folder where you stored your files.
Set the path to the directory of the JDK bin. You will need to run
the jar.exe utility to create a JAR file, and that file is located
in the bin directory.
Create the JAR file.
The format of the command line for creating the
JAR file looks like this: jar cf 'jar-file'.jar input-file(s)
You can use WINRAR.
right click on file (put inside all your .java files) and compile by using winrar;
choose format .zip (important)
and save filename.jar (important)

Create a runnable file from .java files and png images [duplicate]

This question already has answers here:
Add image to JAR Java
(7 answers)
Closed 6 years ago.
I have 2 individual .java files, and in those files, I have taken in some buffered images, which are 3 .png files. I want to turn this grouping, the 2 java files and the 3 png images into a single file that can be opened and executed without a compiler. How do I do this?
You have to build a jar file for this. So you will be able to run your application by double clicking on your .jar file. If you are using netbeans to develop you can simply do it by right click on your application and by selecting clean and build.
I hope this link will help you.

jar file exception [duplicate]

This question already has answers here:
How to make a runnable jar file?
(4 answers)
Closed 7 years ago.
I'm trying to make runnable jar file of my java application. Each time I follow the steps of exporting application etc. It created a jar file for my application but when I run it, it shows popup 'java virtual machine. A java Exception has occurred'.
How can I resolve the issue?
This is correct, JAR IS a ZIP
JAR files are fundamental archive files, built on the ZIP file format and have the .jar file extension
Just run it!

Include external jars while exporting java project in eclipse [duplicate]

This question already has an answer here:
How to export an Eclipse Project with External Jar dependencies?
(1 answer)
Closed 8 years ago.
I have developed a program that includes external jars also. Now I need to convert this program to a runnable jar (It has main method) and place it another location.
But how to include the external dependencies along with this conversion . I dont want other to download the external jars again and again.
Regards,
Siva
Right click on your project then go to Export -> Java -> Runnable JAR File and there select Package Required libraries into generated JAR radio box

how to convert a java project to a jar file [duplicate]

This question already has answers here:
How to create a Jar file in Netbeans
(4 answers)
Closed 9 years ago.
I created a java project using netbeansIDE. Now I want to convert it into an .exe file, but I need to convert the java project into a .jar file first, since java project can't be compiled into a .exe file directly it can be only be converted to exe from jar file. So how shall I convert java project into a .jar file. Please answer in detail since I am a beginer in java programing.
Thank You.
If you are using Netbeans IDE then you can easily build a jar file of your project.
Just go to Run in the Menu above and select clean and build.
Now goto to you project folder, find Dist folder inside it and there you have your .jar file.

Categories

Resources