Converting a jar file to exe file - java

Setup
I am running on windows 10
Have python 3.6 and Java 8
description
I have a Java program which calls and passes an argument to a python program and then receives its output using system commands and cmd.
Question
How do I convert it into a single exe file that is the user can run it without installing java(jdk or jre) and python.
Both are a part of my system variable
Thank you

You can use launch4j application which can convert your jar to an .exe file.
Refer to this: https://www.programcreek.com/2009/05/convert-java-jar-file-to-exe/

Use pyinstaller to package the python file in a exe.
Then in the java program replace xyz.py with xyz.exe
Use JarToExe to convert the jar into a Windows .exe file.
This way you would have two exe files but the user would not need to install java or python

Related

How to run or build a java program using wsl 2

I am trying to use wsl 2 to run java programs, and I will be writing the code in sublime text 3. I have already installed java in wsl 2, but don't know how to run a program through it built in sublime.
First, copy the java file to the linux system, the windows disk can be copied from the mnt directory
Make sure you have successfully installed the Java environment
Use the javac command to compile the .java file,
Use java command to execute .class file

Create executable OSX file on Windows for .jar file

I have created a java program (in Eclipse). I have successfully compiled it to a .jar file which I can run on windows without any problems. I want to give this program to a friend who has a MacOSX. So my aim is to:
Create a file which can be run on MacOSX
The twist is that I have to configure it on my Windows computer since I don't have access to a Mac. Any advice would be of great help!
I am not sure what you are referring as "create a file which can be run on macOSX"
If you want to run on any OS you just need a JRE on that particular system without it you cant run. It will provide a runtime environment to run a jar file. Then use below command to run the jar.
java -jar Myjar_file.jar

Java application export

Okay so I have been coding a game for a while now and I am hoping to release its alpha just one problem. I don't know how to export it and run it. Please note that all my code works fine. So when I export it I export it as a Runnable jar file once I do so I set it and have tried both exporting it as .jar and .exe. Once I exported it I tested it by clicking the resulting file but it doesn't open the application but rather it opens it in eclipse encoded. Please help I may just be an idiot.
you have to try to launch it with:
java -jar yourrunnable.jar
If you plan to run on windows and you want a .exe file, try to check this SO question: How can I convert my Java program to an .exe file?
or if you want to target a mac, you can have a check here:
http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html
Basically any platform you target you have some customization in order to achieve a seamless run. Anyway the most cross platform solution is the Java -jar way.
I had the same problem with .jar files not opening on a double click. It turned out that I had two versions of Java installed (Java 6 and 7). Uninstalling Java 6 from Control Panel-> Uninstall a Program was what finally allowed .jar files to open on a double click without using the command window.
What is listed in right-click-> Open With ? Is some other program listed as the default program ? Is a Java Runtime listed ? If a Java Runtime is listed, you can open with it, and make it the default program to run with.
Right Click -> Properties -> Change -> C:\Program Files\Java\jre7\bin\javaw.exe
For Java 8 use below
java.exe -jar myFile.jar

Possible to run JAR file on any OS?

Is it possible to execute a JAR file on any OS (like Windows, Linux, Mac OS X)? I want to build a simple application that I want to run on Linux, Windows, and Mac OS X. Could the JAR file be run on any OS with java installed?
The Jar files run on any OS for which a JVM exists.
Yes, as long as you don't use any native libraries (JNI) this is how java works. It's platform independent.
As other said, as long as you have Java installed and avoid using native code, you should be good to go. One thing to note is that you can usually run a JAR file just by double clicking it, and it opens like a native executable (on Windows this is how it works by default, on other OSes you can configure this behavior).
Such JAR files are called executable JAR files. If what you want to create is an executable JAR file, then you need to add a manifest file that tells the Java virtual machine (JVM) the name of the main class. Executable JAR files also can be run on the command line by doing:
java -jar myprogram.jar
If your JAR is not an executable JAR, then to run your program you have to add the JAR to your classpath and then execute the main class. To add a JAR to the classpath:
java -classpath path/to/your/program.jar com.mypackage.Main
Jar files are designed to run on any OS that has a JVM of a compatible version installed. Some jar files, however, may have be compiled from Java code that used OS-specific code (say talking to Windows registries), so testing it on other OS's is wise.
Yes, it can as long as it's not ruining from the terminal or command prompt (like java -jar name.jar.) it should work just fine.

Jar file of java

I have created a java application and packed it into a jar file on a Windows platform. Now I wants to deploy that jar file on Debian Linux.
Will the same jar file work for Debian Linux?
Is the command, used in windows for executing a jar file from the command prompt, same for Debain Linux?
i.e.
java -jvm "MyJar.jar"
Will the above command work for Debian Linux?
Generally, it should. However this depends on a few conditions:
If you use native code (JNI) you must make sure that the native library is available for the target platform
You must make sure you have no paths hardcoded which are Windows specific (in fact you should even watch out for special characters like the Path seperator : vs. ;)
You cannot use Runtime specific code
Yes.
Jar files are portable across platforms, and the syntax of the jar command is the same on both Linux and Windows.
EDIT: You should use the latest version of Sun Java unless there is a very good reason not to. Installation instructions: http://wiki.debian.org/Java/Sun
1. Will the same jar file work for Debian Linux?
Yes. Hence the nature of Java (portable code)
2. Is the command, used in windows for executing a jar file from the command prompt, same for Debain Linux?
java -jar "MyJar.jar"
yes, the main idea of java is that it (should) run on different operating systems, as long as a java runtime is installed.
though i have never heard of the -jvm flag.
if you want to start a jar file you should use the -jar flag.
java -jar "MyJar.jar"
you can also read up on the Write once run anywhere principle.
I do my development on a mac but run in linux and windows environments without any problem. Key is not to use JNI, As everyone else have mentioned I would use java -jar "MyJar.jar"
Almost. Use:
java -jar "MyJar.jar"
And of course you shouldn't have used anything such JNI or runtime stuff
Yes, although you might want to do, in Linux:
java -jar YourJar.jar
Instead of:
java -jvm YourJar.jar

Categories

Resources