I made a simple card game using Eclipse Kepler. I then exported it to a runnable .jar file.
When I double click the .jar file, nothing happens. So I made a .bat file:
java -jar CardGame.jar
When I run it, it works fine, but when my friend runs it on his computer (yes, both files in the same directory) the cmd.exe will tell him: 'java' is not recognized as an internal or external command
After some searching I read that I had to add %JAVA_HOME% in the .bat file. This made no difference for me, but it will still not run on my friend's computer.
So my questions are:
- What is wrong with my .jar or .bat file?
- Can I run it without the .bat file, if so how?
He needs to have Java installed in the default path.
The easiest way to get that is to go to http://java.com/en/download/installed.jsp and follow instructions until Java is reported installed.
After that your friend should be able to run it.
EDIT: OK, I think I was being silly. What I really wanted to do was a runnable JAR. I did and now it works.
So I'm trying to run a little program that interacts with some webpages. The program works fine when I launch it from Eclipse but when I export it to a jar file and try to run it from the command prompt I get this error message:
What am I missing here?
I'm assuming in Eclipse you've added the appropriate libraries to your build path. When you run your program through eclipse, it automatically creates a java command including all your libraries in the classpath.
You need to do the same thing
java -cp /path/to/libs -jar muzictest.jar
so I have this problem. I have an aplication, which is using Runtime.getRuntime.exec(adobePath) to run Adobe Reader.
When I run my aplication using NetBeans or from cmd line by using java -jar "MyApp.jar" it does work fine. But when I run jar file by double-click or from cmd using MaApp.jar it doesn't work. I'm using Windows 7.
What can be wrong?
Thanks
edit: Maybe I said it wrong way. When I run jar file by double-click it does run. And it works, but when Runtime.getRuntime.exec(adobePath) is called nothing happens. And It work fine in NetBeans or when I run App by java -jar "MyApp.jar".
Right-click on the jar and see under Open With ?
Make Java Runtime as default program to run with.
I created an executable jar file with eclipse indigo, but when i double click on it nothing happens. But when i write java -jar c:/dir/filename.jar to cmd, it works. Other jars runs well. I'm using jdk 1.7.0_02 and eclipse indigo. How could i start it normally?
You can run a jar by double clicking it, you just have to make sure that Java is associated with .jar files. The easiest way to do this is by reinstalling the JRE (which generally does it for you).
Otherwise you will need to modify some of your Windows properties (I'm not sure what version of Windows you are running) to point .jar files to the instance of javaw.exe.
Here's a link to a Windows 7 page on how to do it.
right click on .jar file and go to properties, then set "open with" program to "Java SE Binary".
You can do this by associating the .jar extension with the command to run it via javaw.exe.
"C:\Program Files\Java\{java version}\bin\javaw.exe" -jar "%1" %*
I'm writing a simple Swing application in NetBeans and doing so on an Ubuntu machine for the first time.
As many of you know, NetBeans automatically creates executable JARs for projects that are "set as main".
On Windows, you can double-click an executable JAR and it automatically invokes the JRE and runs the app. In Ubuntu, double-clicking the .jar file causes the file to be opened in the archive manager instead. In order to run my JAR, I either have to right-click it and select "Open with OpenJDK Java 6 Runtime" or launch it from the command line.
From the command line I get no problems whatsoever. However, when I try launching it from the right-click menu, I get an error that reads:
The file MySwingApp.jar is not marked as executable...
So I have 2 questions:
What do I have to do to set it as executable? Is this something I can do inside NB or do I have to use the shell? If I have to set permissions via the shell, doesn't that conflict with NB's policy of auto-generating **executable** JARS? And what command would I use to flip the executable bit anyhow?!?!
Is this just a Linux hiccup? I want to send this JAR to friend who run Windows and I'd like for them to be able to just double-click it and have the program launch
Thanks for any helpful suggestions!
You will need to manually tweak your build process to get the jar file marked as executable in Netbeans. Go to your project root and open build.xml. The header has instructions on adding to the build process. There is a target, "-post-jar", that is called after the jar is built. You'll need to make that target and use Ant's chmod task to modify your jar. Once you do that it will occur every time you make a jar file in that project.
It will run fine on your friend's Windows machine, as long as he has a JRE installed.
Here is a thread about running jars using double click in Linux.
You can Java like a native binary on Ubuntu (and other linuxes), it's a feature of the kernel. You need to install the binfmt-support package to give the kernel the hooks to run java in this way.
In Ubuntu open up a terminal and run:
sudo apt-get install binfmt-support
Then make your JAR file executable
chmod a+x yourjar.jar
Then you can run your JAR like any other binary by typing
yourjar.jar
Jar-files aren't first class executables, and they don't become magically executables by changing their executable flag.
If you execute a jar, you run the command
java -jar YOURJAR.jar ...
It's the same, as if you double click a png file, and expect it to run in a painting program
gimp YOUR.png
You don't need to make your png an executable one, and it will not solve a problem.
Instead, you have to tell your desktop environment, what to do when double clicking a jar or png-File, and you have to do it on Linux the same way you do it in Windows - maybe the installer on Windows does it for you, because there is normally just on Desktop Environment (Windows) on the OS (Windows), but Linux has Gnome, KDE, XFCE, LXDE, fluxbox and millions more.
And it isn't so sure what you want to do with it. Since jar-files are a special form of packed zipfiles, usually containing a Manifest and the classes, the Archivmanager isn't a false solution, and it is saver to show the content of the archive, than executing it.
Copying the file to windows has no effect. Windows not even has an executable flag, but you shouldn't fiddle with it though. You change your desktop settings, and those can't be moved to windows, and you will not want to.
And if you have the correct settings in your DE, you don't need to tell Netbeans or any other IDE repeatedly, what to do with jar-files.
I gone through Internet and I came across one article with complete steps to run jar file
http://mlartist.blogspot.in/2012/07/deployment-netbeans-project-in-linux.html
Jar files are basically a zip file, to create an executable, you have several different methods. The Best (in my opinion) is to use ant to create it. Or you can simply echo "Main-Class: YOUR.MAIN.CLASS" >> Manifest and then create your jar by jar -cmf Manifest JARFILENAME.jar INPUTFILES then, to make it executable under linux, right click on it and click on properties. Then click on permission tab and check execute. or you can be a terminal bamf and cd to the jar directory and chmod +x JARFILE.jar
HAPPY NIXING!!