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.
Related
I created a project that contains a JFrame and other JObjects. It also contains picture and other classes that have their own JFrame and JObjects, but I can't seem to get the .jar launching correctly.
I'm using DrJava and I'm not sure what I'm doing wrong. I clicked "create .jar from project", I put the main class in the text field, and it should create a .jar file. Except, when I look at the file, it's not a .jar but just a file.
If I change it to .jar it doesn't run. If I open it with WinRAR my classes and pictures and everything are in there. If I try to launch it in DrJava it immediately says "Execution of jar file terminated (exit value =1)".
As it's creating the .jar file, I get an error, it has all my classes under why and it says "Duplicate: (Insert one of my classes)$", but it says that DrJava was probably able to recover. After a second or two it says ".jar created successfully". If I try to launch it in CMD it doesn't open and I get a whole bunch of line errors, but if I compile it in DrJava it runs perfectly.
Why is this?
Because you didn't add a Main Class to run the program. I think you can add the main class using project properties in Dr.Java As in this Dr. Java
A file opened in DrJava probably has to be saved as a .java file. Its one of the many shortcomings of DrJava
I am trying to create executable jar out of a java project. the java project has the main method in a java file named MainTest.java.
To create the executable jar, I did the following:
right click on the project->export->java->runnable jar->next button
Then I get a window with a list asking me to specify the launch configuration, the problem is , despit the java project has a main method in the file namedMainTest.java, this file is not listed in the list
how to solve the problem or how make the java file that contains the main method listed among the others in the list.
Note: the namedMainTest.java has the main method but it is empty "does nothing"
update
I am using Eclipse.
and please have a look at the screen shot below. on the left , is the project with the java file that contains the main class "MainTest.java" and on the right, a list of classes and the "MainTest.java" is not among them instead there is another class names "TestMatrix.java" and i do not know why it is there
I'm assuming you are using eclipse?
Your desired main function appears if you ran your program before it. The dialog tells you to select a "run configuration". Since your main has not been run yet it does not appear.
Another way to generate an executable jar is by going this way:
Export>Java>JAR file>
At this dialog select the resources to be exported (your project e.g.) and specify
the name and destination of your jar file.
After that continue (2x next) to the "JAR Manifest Specification" screen.
The last option asks you to specify your Main class. Press finish after configuring your project and you are done.
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 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
My eclipse seems to be pretty screwed on my laptop. Whenever I load a program up from College, it does not detect the errors or anything. Also now when I attempt to run the program, it won't allow it; i'm given the message
unable to find an ant file to run
Anyone able to help me out?
1-Create a new project in Eclipse
2-After the project is created, look in the package explorer window pane on the left and right click on the src folder.
3-There are two methods for the next step, you could either add a New > Class, and then copy and paste everything from your old java file to the new class (make sure the class name is the same), or the better route would be to Import.
4-After clicking Import, select File System under the general folder. Click Next.
5-Browse for the java folder where your source files are located. Once you click ok, it will add all of the source files to the right pane.
6-Select which files you want to add and click Finish.
7-Now if you look at your Package Explorer window you should see the source files. Now just
compile them, and the error shouldn't appear and you can run them just like before.
By creating the new project, you're making sure Eclipse knows where your source files are located (in ./src) so that it can compile your code in that location.