eclipse exports the project fine as a Jar, but when I double click the project it won't load up.
Can someone please tell me whats wrong. I know that while creating java executable in command line we are supposed to create a manifest file. Is it same for eclipse, if yes then how and where am I supposed to create the manifest file. Or if eclipse creates it for us then what else could be wrong?
Go to file->export->runnable jar and select the class which contains the main method.
Setting .JAR File Association
Normally, the installation program for the Java 2 Runtime Environment will register a default file association so that .JAR files will execute with 'JAVAW -JAR' by double-clicking any .JAR file. If this does not happen, or it somehow gets changed, then manually setting the association for *.JAR files may be needed.
Open the Windows Explorer, from the Tools select 'Folder Options...'
Click the File Types tab, scroll down and select JAR File type.
Press the Advanced button.
In the Edit File Type dialog box, select open in Actions box and click Edit...
Press the Browse button and navigate to the location the Java interpreter javaw.exe.
In the Application used to perform action field, needs to display something similar to "C:\Program Files\Java\j2re1.4.2_04\bin\javaw.exe" -jar "%1" %* then press the OK buttons until all the dialogs are closed.
Now you should be able to launch any *.JAR program by double-clicking it.
This step by step guid was taken from: http://windowstipoftheday.blogspot.com/2005/10/setting-jar-file-association.html
Related
when I run the project compiler says BUILD SUCCESSFUL but not any window is appear. when I runt the project I want to start main_window as a default window. but I have no Idea how to setting up this.
If you are creating a jar file (as I assume you will be doing from your previously deleted question), the main class would be specified by the jar file's manifest.
e.g., the manifest file, named MANIFEST.MF could contain a line looking like:
Main-Class: gui.main_window
Right Click on the Netbeans tool-bar. An drop down menu should appear. Select Customize and scroll down through the options until you see Run File. Drag the button onto the tool-bar. Now select the main_window.java and hit the Run File button.
The IDE should run only the file.
I have seen other posts about this but I honestly don't know what to do with that information. Can someone explain to me what exactly I need to do please?
I'm using JCreator
With JCreator you can follow the below process.
Click on Configure/Options.
Click on Tools in the left column.
Click New, and choose Create Jar file.
Click on the newly created entry Create Jar File in the left column under Tools.
Edit the middle line labeled Arguments: it should have
cvfm $[PrjName].jar manifest.txt *.class
Click OK.
For more information you can refer this article
Assuming you are using eclipse: Right Click on your project->Export:
Export it as an executable JAR. That will allow you to run your program directly from that jar file.
It really comes down to what IDE your using, some have that ability, directly under the menu "file" or "project", where you can them select "export as". Some IDEs however, do not have that ability and only allow you to export as a jar file. If that's the case, you need a third party software to do that for you.
An IDE is the platform you are using to debug your code.
I've done a search and I can see that a lot of people have had the same problem as me, but none of the solutions have worked for me.
Basically I have a Java Project in Eclipse that is from my old Windows Installation. I've cleaned and rebuilt it because at first it wouldn't compile, but now I have it exported as a Runnable Jar. However, the only way I can get the application to appear is to do java -jar foo.jar in command prompt, or run it in Eclipse. If I double click the JAR in Windows Explorer nothing happens even though I know that Java is associated correctly because other Runnable Jars work.
The project only has the x86 JRE listed in it's Build Path Libraries and all the files listed appear to exist. I'm running Windows 7 HP.
Update: I'm sorry, but I just discovered that no other Runnable Jars are working either. If they are wrapped with launch4j they work though...
Edit: The Runnable Jars that I export from Eclipse do work fine on other systems and load on double click
Some registry values or file associations are probably messed up. Wiping off all of your existing JRE's and JDK's and re-installing them should fix your issue.
Alternatively you may be able to fix it by manually editing the registry value here:
HKLM > SOFTWARE > Classes > jarfile > shell > open > command
My value is
Type: REG_SZ
Data: "C:\Program Files\Java\jre8\bin\javaw.exe" -jar "%1" %*
You'd of course want that path to point to your javaw.exe, and make sure you have the additional arguments.
I was also facing the same problem while i was working with Spring tool suite.
You may use the following steps:-
Right click on project -> export -> Runnable jar file -> (Here,In library handling,there are three options,you have to choose middle one i.e package required library into generated jar.It will package external dependency also).
-In my case, my runnable jar was only executing on my environment i.e on which i have created that JAR. Initially i have selected the first option to create JAR i.e extract required libraries into required JAR.but that was not proper.
It may help you.Let me correct if i am getting wrong.
Since you are able to run the JAR running the command line, I believe your issue is related to which version of Java is set to run the file when it is double-clicked.
To find out which version is successfully running the file from the command line and set it to open JAR files by default:
Open a new command prompt window.
Run echo %path%. Among the path values, you should be able to find one pointing to the bin folder of one of the installed versions of Java. Copy this path somewhere.
Navigate to the JAR file you would like to run. Right click the JAR -> Open with -> Choose default program... -> Browse...
Browse to the path you copied in step 2. (the easiest way is to paste it into the address bar)
Double click javaw.exe.
Click OK.
You should now be able to run the JAR file. Please let me know if your problem persists.
I have made a jar with and keep it on desktop.Then,I double clicked on the jar and it working fine for me.
How I and what I have monintored: In my main class, perform some operation and at the end I add on Thread.sleep(25000); to hold the program for few moments. After every double click on the exported jar I found one new javaw.exe process added in the system process tree. I have noticed it on Task manager. and after 25000ms respective javaw.exe process ended. As my application does not cointain any GUI that's why I have not seen any GUI changes for the respective process. I'm Confident that if my application have some GUI, I will surely get the respective GUI window on every run.
Common mistakes : when we export a project from Eclipse as Runnable JAR file, it is exported with selected Eclipse launch configuration and Eclipse specific launch wrappers. Now if the configuration does not match when you are trying to run it via double-click you will not be able to see the error, If you run it from CMD then surely you will get the error log.
To create standard executable JAR file : To create a standard executable JAR file, you can export as JAR file and specify the main class in last screen of the wizard.
That's working for me fine. I used the same jar from different system and keeping it different location.
I already read many questions it the same subject, but none solved my problem..
I know that I can easly launch my app using this command on console java -jar myappname.jar
But what I want is to click on my .jar file exported by eclipse and it launches console with my app inside, do u understand?
I done the export using this configs :
File>Export>Jar File
Selected all the classes of my project
Selected "Export generated class files and resources"
Selected "Export java source files and resources"
Selected "Compress the contents of the Jar File"
Pressed Next
Selected "Export class files with compile errors"
Selected "Export class files with compile warnings"
Pressed Next
Selected "Generate the manifest file"
Selected Seal the Jar
And on "Select the class of the Application entry point:"
I choose my class where is the void main method .
the jar appears on my desktop, but then, when I double click it doesnt launch the console. why??
Thanks in advance!!
Launching a jar by double-clicking the file (or shortcut) will not display a terminal. One workaround is to change the default execute action in your operating system for .jar files to open a terminal and execute the command from within the terminal. A script like the following might do the trick (using Bash):
#!/bin/sh
/usr/bin/gnome-terminal -x java -jar $*
sleep 3
Then right-click on the jar file and choose the script as the default program to run for that file type.
Disclaimer: the above script actually fails for me. It works fine if the command being run in the terminal is "top", so it looks like you may need to tweak this a bit.
It depends on your OS.
If you use Windows, you can create .bat or .exe files. You can find 'how-to-create' tutorials on the internet.
If you use Unix based OS, you can just set the jar to be the executable.
A third party OS probaly has it's own way to set to executable.
This is the only way I am aware of.
I wrote my Java application in Eclipse. Now I would like to generate a .jar file which can be run on other systems from the command line. Is there a easy way to do it in Eclipse?
In particular I am wondering what should I do with the jar files of external library that I use (should it be included into my .jar file?).
Moreover, should I generate some manifest files?
ADDED:
I see the window in which I can choose "Extract required libraries into generated JAR" or "Package required libraries into generated JAR" and so on. I select the first option, I specify export destination but "Next" button is not activated yet. What else should I specify. I am offered to launch a configuration but i do not want to. Every configuration is associated with a fixed set of parameters given in the command line and I do not want that.
Select you project, then Export => Java => Runnable JAR file
You can then choose to extract/package/copy required libraries into your JAR and also select the class, whose main() method should be executed on startup.
Then you can execute the generated jar via:
java -jar yourjar.jar
When you go to Export => Java => Runnable JAR file,
You said "Next" button is not activated yet, You don't have to press the next button because you can just press finish, If you don't want the Lauch Configuration, You can manually edit the manifest file later. If you have external libraries you can chose one of the options they give you, extract/package/copy required libraries into jar file