Running a jar2exe file as jar from command line - java

I am trying to run the NetBeans exe without having a JDK installed to the system, however, I have the 1.8 JDK unzipped to a flash drive. When trying to run the NetBeans exe as a normal jar file using
E:\Java\jdk1.8.0_60\bin\javaw.exe -jar E:\Java\NetBeans\bin\netbeans64.exe
it says that the jar file is corrupt or invalid. To my knowledge, the exes made from jar files are just jars wrapped to an exe, so I have no idea why it wouldn't work this way.

EXE files cannot be ran using java -jar or javaw -jar command only JAR files can be execute like that.
If you want to use mention JDK that netbeans runs on use netbeans.exe --jdkhome <jdk home>
In your case the command will be
E:\Java\NetBeans\bin\netbeans64.exe --jdkhome "E:\Java\jdk1.8.0_60"

Netbeans uses Java environment to initiate its installation. Exe and jar are two different files you cannot run exe file via javaw.exe -jar

Related

Wrap a executabe jar into .exe for using without jre installed

I would like to wrap an executable jar into a .exe file in order to give it to associate. I used Launch4j and it works. However the others are not able to use it. Error occurs always with Java version.
I found this question:
Running a java program as an exe in Windows without JRE installed
Is there nothing else more easy to use?
EDIT :
I slected prefer JRE rather than preferJDK und JRE window, that was the problem there.
In Launch4j, under JRE > Bundled JRE path, type something like ./runtime. When you wrap your JAR file into an EXE, the EXE will look for a java runtime in the current directory under a subdirectory called "runtime". If you copy a Java runtime directory into the same directory as your wrapped EXE file, it will use it.
In Windows Explorer:
The "runtime" directory is the complete JRE directory, E.G. "jre1.8.0_201", but renamed. Inside there should be a bin folder and a lib folder and some other files.

Let jar file run in cmd or terminal on mac

The program I write in Eclipse runs on console purely. I hope to export it to a jar file then use launch4j make it an executable .exe file. The program should desirably be opened in cmd or terminal on Mac once clicked. But it seems I can't open it with cmd and unless I used swing or awt, nothing to show when I clicked either jar file or exe file. So what is the problem and how should I do to make it runnable on cmd!
PS:I dont want to type any command line, just click the jar file or exe file and it started to run on cmd or terminal!
You would possibly try script files for this task:
windows: run.bat
java -jar your.jar
mac: run.sh
#!/bin/bash
java -jar your.jar
launch4j could work on windows/osx/linux, but I think you need a mac to build the executable file. And the jar file itself can be run when double-clicked, if you specify the Main Class in META-INF/MANIFEST.MF file, like this:
Main-Class: com.xxx.xxx.YourClass
After this, the jar file could be double-clicked to run.
This Answer shows the use of Jar Bundler to convert jar to executable native Mac OS X .app executables
I think you can give it a try. Enjoy!
Edit
Jar2Exe seems promising to convert jar file to executable for Windows and Linux Platform.
You can try them and let me know too if that work for you.

Which files other than .jar needed for making an installer

I had completed building a .jar file for me project (media player), it is also running successfully with command line java -jar mediaplayer.jar.
But now i need to make an installer, so what all files do I need for making an installer, do i need to bundle the lib files also with the installer.
also when i launch my .jar file with Java Web Start, it says "Unable to launch application"
You definitely need to bundle both your mediaplayer.jar and the libraries in your classpath. You will also need to generate a native executable file that will at least do java -jar mediaplayer.jar.
Usually native launchers also check if Java is installed on the target machine and help user to install it if it is not.

Executable jar doesn't start normally

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" %*

Executable JAR on Ubuntu (NetBeans)

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!!

Categories