Run exe from java on Linux - java

I am not sure if this is possible, I wanted to run a Windows exe application from the command line from my java program - something like
Process process = Runtime.getRunTime().exec("myapp.exe --params");
The catch is that I would like to run the java application which calls the exe from within an OS X or Linux environment.
I was wondering if anyone has done this or has any suggestions on how it could be done? Thanks
Edit: thanks for responding. I did want to add that I would probably not want to use wine to run the exe and would probably want to create some type of wrapper around the exe file to call functions from the dll directly from java. I haven't done this before and was wondering if any pointers on this.

exe files are have a specific, Windows-only format called Portable Executable (PE). It's not compatible with the format Linux uses for executable files, not to mention differences in system calls between the two systems.
You can't just run an exe file on Linux, regardless of whether it's being run from Java.
If you really need it to work, you have two options:
Use a Windows compatability layer for Linux in the form of WINE (or similar tools)
Recompile your exe for Linux

Related

How do you export a Java project to an EXE without needing Java to run the EXE?

The Title is probably worded weirdly.
I've been using Jarsplice to convert my Jar files into Exes and they're able to run properly. But when I try to run the exes on different computers it would say that Java is required to run the program. So I just wanted to know if anyone knows how to and what can convert jar files into exes without java being necessary to install on other devices.
You can also use GraalVM. This brings an app called native-image, which you can run like this:
"D:\apps\graalvm\graalvm-ce-java11-21.0.0.2\bin\native-image" -cp "D:\workspace\HelloWold\bin2" Main "D:\workspace\HelloWold\release\HelloWold"
And which will output a standalone .exe file.

Run a Java application on a Mac

i am currently developing an application on my Windows laptop however I also need it to run on a Mac. Is there a way to either convert my project to .dmg or .app or create a mac build striaght from Windows Eclipse?
I would very much rather not have to install Eclipse on the Mac machine just for this as it is a one time thing. Any Suggestions?
In my experiences you need a Mac to create anything for the Mac/iOS platform. So I guess you need a mac to create a dmg file.
Here is a post that says how this can be accomplished.
Of course you can just run the jar from the command line.
run on any Java virtual machine. It does not matter if you run it on a mac or pc, that's the whole idea with java
Any simple way of creating a dmg file will probably require a Mac, however you don't need to do that; after all, you don't create an exe when you run a Java program on Windows either. Instead export it as a jar file and it should work on both systems (provided a Java Runtime Environment is installed and is set to run jar filed).
If you insist on creating a dmg, check this question which discusses creating them on Windows.

Is it possible to convert a jar to exe using Ant build in Linux?

I have created an project and need to distribute it over Windows. I need to create an exe for it I already know that there is a lot of tools like:
JSmooth
Launch4J
Executor
Advanced Installer etc.
The installer windows are done in Java itself. Means like the selecting locations, licensing etc. the only thing I need is to create an exe that should open this jar. Is that possible in Linux?
For a Java app. with a GUI, Java Web Start is the best option. It is supplied and maintained by the maker of the JRE, and therefore works on Windows, *nix and Mac.
I do understand the need for an .exe on Windows and I've used JSmooth before.
I would just make a shell script which launches the program. I think a shell script is fine for Linux: icons aren't built into the executable and you can't discover the location of a usable JVM automatically.

Is it possible to convert an exe file to a jar file?

Is it possible to convert an exe file to a jar file?
Because I just made a game which is online and in .exe file format, and I have a server running linux. It may be possible to run the exe on the server, but one of the two ways would be very good for me!
So the ways are either:
Convert EXE to Java, or
Run EXE in Linux
is impossible. EXE (actually PE) is the binary format used by the Windows family of operating systems. It contains assembled machine code and import and export tables to interact with the operating system. JAR contains java bytecode. Sadly, they are not compatible (actually the JVM generates machine code from the Java byte code on the fly, but the other direction is not possible AND makes very little sense, too …).
Check out Wine. It emulates part of the Windows API so it can run a subset of all native Windows applications.
You can run EXE on Linux under Wine (unless you use DirectX or alike), but what's the use of it? Is your game a server side of some distributed game (i.e. game server with clients running on the client computers)?
Upd: One more option is to run a virtual machine with Windows inside on your linux server. This can be more viable.
Is it possible to convert an exe file
to a jar file.
Not unless the exe was made by Java source. and you have the source code. but then it isn't a conversion, its a recompilation.
Run EXE in Linux
Wine will run windows executables. But if you have the source why not just run it with java?

How to generate an exe file from my java project ? Which tool should I use?

I was asked to make a program (in java) by some person but I was stacked as I didn't know how to generate and exe file from my jar file... It would be useless If I install for them the jdk environment as this person don't how to program... Does anyone knows ho to do this or what tool should I use ?
Regards from Córdoba Capital, Argentina...Thanks in advance !!!
You could use launch4J, it's pretty simple to use and to configure.
Read this post, it may help
http://viralpatel.net/blogs/2009/02/convert-jar-to-exe-executable-jar-file-to-exe-converting.html
Regards
Thomas
Here is a post from earlier that has some other options:
How to create a Java application which can be run by a click?
As Lucas mentions above, you will need to install the JRE on the user's machine to get a Java app to run properly. If it is a small program, you could consider making a .bat file (or .sh file on *nux) to allow the user to run the program. Your bat file could as simple as the one below. Just put in a .bat file and add as a short cut. I know there are more elegant solutions out there, but this is simple and should work.
setlocal
set CP=<PATH TO ANY DEPENDENT LIBRARIES OR JARS>
start javaw -cp %CP% <FULLY QUALIFIED MAIN METHOD> <PROGRAM PROPERTIES>
endlocal
They don't need to install the entire JDK to run the jar file, all they need is the significantly smaller JRE. This is standard practice when distributing java applications.
A big advantage of running your java program on the jvm as compared to generating a native binary is that it will, assuming you aren't using a platform-dependent library, be platform-independent straight away.
You can use Excelsior JET. It is not free, work quite slow, but you can create executable (very huge executable). I tested it on Windows and it worked. But executable it created was slower then .jar run using JRE.
There is also GCJ. I tried it, but it was too hard for me to compile my project.
I suggest installing JRE and working with .jar file.

Categories