This question already has answers here:
How can I convert my Java program to an .exe file?
(16 answers)
Closed 8 years ago.
I have one library, one txt file for import some things with it and one output file to show the result. Only have one java file without any interface. With eclipse all is running well - I am writing into the input file and then it shows the result into the output file. Now I want to make this all independent program (without need to run with eclipse).
How to make it?
An easier way is to make a runnable JAR file.
Go into eclipse choose file > export > runnable JAR.
It will then ask you to choose a class for a launch configuration. Choose the class that has the main method for the desired program. After that you will have a file that will run (like a .exe but just a different format).
If can't get it to work with your input and output files, thats because eclipse has this weird thing that sometimes occurs regarding the location of external sources when exporting to JAR. To fix it, just put the files instead of the src (source) folder, one folder up in the directory. For example, if this is your current directory: C:\workspace\myprogram\src put it in C:\workspace\myprogram
Hope this helps.
The only thing that eclipse is is a software that facilitates progtammi g. But what find the programs is the jvm-java virtual machine. To get to the point eclipse does have a option to convert it to a .jar file which the extension a java program uses to be "independent" from eclipse and open up by double clicking. The way you do this is you right click on the class you want to make independent and I think there should an option that says export to .jar and that should do the trick! Hope this was helpful
Related
I have three classes, one of them is called Main and contains a main method, and no package. The IDE I use is eclipse. If I click File > Export and then select Java > Runable JAR File I'd expect to get a file that I can double-click and that'll run my program. However, that's not the case. If I click the resulting file nothing happens. I'm very new to this whole thing, so my questions are: Is this file even supposed to be clickable, or am I missing a step to run it? If that's the case, how to I convert the file to a .exe file (I really don't get this manifest-stuff, so please explain in detail how that needs to be done)? Basically: How do I create an executable (executable as in "works if i just click on it") file from three classes (with eclipse if possible)?
Edit: It's a console app.
Friend cannot open an exe I made from a jar file. Gives a java exception, assuming that simply means he doesn't have the correct version of java, is there a way for me to include the files needed to run it with the exe, to remove the need of having java downloaded?
I made a java program with jframe for a friend to help him do some calculations and I was able to convert it into an exe but when he downloaded it and tried to run it, it gave a java exception, is there a way I can include the java files needed to run the app with the exe?
You have to first create a .jar file and then convert it into an .exe file. You can refer to this link https://medium.com/#sulabh4/how-to-make-a-executable-file-from-your-java-code-3f521938ae5c
This question already has answers here:
How to includes all images in jar file using eclipse
(4 answers)
Closed 6 years ago.
I have an image file which I want shown as a JLabel in a JFrame for a program that will be on several computers running the same code. The image would not be on the computers already but would somehow be stored as a program file. The computers would all be windows. To insert the image a file path has to be given, but I'm not sure what this will be considering the computers are all different.
I have done this before on a different language by having the program find the program's directory and doing some string manipulation, but I have not been able to do this yet on java and would like to know if there is a better way.
Here is the statement that the path has to go into:
lblTitleBG.setIcon(new ImageIcon(file path goes here));
lblTitleBG is a JLabel.
First you create a source folder inside your project using eclipse or your preferred IDE. That will create a physical folder in your project folder that you can navigate in and move your files.
Let's say you have Project1 where you create Files_Folder. Now you navigate to the Project1 folder with window explorer and paste the files you need inside the Files_Folder and in the bin folder too. After this, just go back to eclipse and refresh/clean project. Your new moved files will appear in the Files_Folder in eclipse explorer too.
Just use lblTitleBG.setIcon(new ImageIcon("Files_Folder/image.png")); after following all the steps and you will have portable code.
Try to pay attention to steps and everything will work good. And finally, when you export your jar, don't forget to keep the Files_Folder in the same location to the jar, in order to find and use the needed files.
This question already has answers here:
Add image to JAR Java
(7 answers)
Closed 8 years ago.
I am trying to export my Java project using Eclipse's function but when I run it, it only shows the background, no external files. I used customized Checkboxes and Button, but they don't show up. Running it from Eclipse works perfect. This is the hierarchy for my Game:
.settings(folder)
bin(folder)
src(folder)
.classpath
.project
some .png files
This is how it looks in eclipse. I don't know what is with the red exclamation mark on Game.
These are the steps I took in creating the runnable JAR file:
I added my pictures to the Build Path (Skipping this step has the same effect)
I clicked Export - Runnable JAR file:
Then:
When I clicked finish, I had no warnings:
Why did you put all those images as referenced libraries? You should just put them in the src folder.
Any way, have you specified the main class when exporting the executable jar file?
Can you explain what happens when you try to execute the generated jar file?
These warnings may not be related to problem. But if you show them, it may be easy to check.
If I didn't get it wrong, Eclipse will only pack things in bin to the jar file. So you got two options:
Leave things as it is, but when deploying, put the images in the same folder with the jar file.
Put your images in src (so it would be copied to bin and hence packed) and change your way to access your image: get the URL with getClass().getResource() and read from the URL with something like Toolkit.getDefaultToolkit().getImage().
This question already has answers here:
How to make Java program installable?
(6 answers)
Closed 9 years ago.
I made some programs in java but I don't know what I should do afterwards finalizing it for the end user. all I have is a bunch of .class and .java files in a directory and I have no idea how to distribute it to the user. Isn't java supposed to work like a normal program where I install it through a self-extracting file or InstallShield like how pc games install their programs? Thank you.
I've read on deployment but mostly I saw was how to package it into a .jar file. I'm not sure how that works but the user would most likely not be able to know what to do with a package file unless I include detailed instructions on how to operate it. I was hoping there would be a way that I install the entire java program with a .exe file like a normal program does and it will load up into a specified directory and create start menu/desktop shortcuts for the user to use.
Thank you in advance.
.jar Files are runnable on each Plattform. That's the advantage of java. So you can roll out the .jar or you can run it into an Java-applet. Or you build an .exe launcher...
Like this:
https://stackoverflow.com/a/15409917/2617699
Export it into an executable jar using eclipse. The you can create an exe using Launch4j or any similar software.