drag and drop files into a exe java - java

I want to build a java program that will take a python file and drop it into a .exe, thus starting that .exe and running the python file in it.
I have converted the whole python library into a .exe and I have build a boot system on it that just needs the python file to be dropped onto it. I have made this file so I can run python on PCs that don't have python installed. I would go with the .BAT method but so 32 bit systems have a hard time with batch drag and drop.
So I am asking for some code that would allow me to take a file and run it through another file. I hope this is the information you needed, if you need any more i will answer it!

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 exe from java on Linux

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

File to open terminal and start .jar in OSX?

I currently have a small text game I've written in Java that utilizes System.out.print(); to output text and a Scanner to receive input from the user.
I've compiled the runnable .jar and used IExpress to create a .exe that runs the batch command java -jar "foo.jar" upon execution. It's not the best way to distribute the game, but it's a quick way to distribute it to friends for play testing in Windows.
I'm wondering if there is an equivalent for this for OSX? I know I can write a shell script to open the terminal and execute the .jar file, but will it work if the shell script and .jar are distributed to other computers? Does each person have to give the .sh file "execute" permission? Some of these people aren't really tech savvy and even mentioning opening terminal would turn them off to helping me play test.
So is there a way to give them something to double-click on that will open terminal and run my .jar?
Thanks in advance!
Here are two possible options (the first of which will probably not open the terminal, but I'm leaving here in case you find a way to do so with the below mentioned JarBundler)
1 - Building a native java application bundle and installer
The answer is somewhat two-fold. OSX applications have a specific directory structure which the operating system expects to be in place, they are called application bundles (google for "osx application bundle programmers guide" for the messy intricate details). Jar Bundler is an Ant task which can build a bundle for you without you needing to understand the bundle format itself.
That alone is enough to allow you to drag the application onto the OSX dock. However, what is more common is an installer. To build an installer, you need to build a DMG file. Some good documentation on how to create this with ant can be found here.
The gist of it is to create a disk image, attach to it, copy your application into it, detach from it, and compress it. A typical OSX installer is a window with a copy of your application and a symbolic link to the /Applications directory. When the installer window opens up, it displays both of these items and you normally drag the application to the /Applications icon, "installing it" (in reality, just copying it to /Applications).
The following the relevant Ant build files from my project for building an application bundle as well as building a DMG file (both are google-code links). They do not require any of the GUI tools.
Both of those files are pretty heavily commented.
However, I have a feeling this will not open the terminal window as you desire (you may be able to work with the stubfile option in JarBunder to get it to do what you want).
2 - Create an application bundle from your shell script
This link shows you how to create an application bundle out of a shell script.
You can then create a DMG file out of your application bundle to simplify installation for your users. The DMG file will preserve the execution file attributes so they will not need to manually chmod +x your script.

Creating a stand alone Java application

Is it possible to create a stand alone application in Java (using Swing) and package it into an exe file?
My Idea is, we should be able to double click it and run the application.
If you export a runnable .jar file you will be able to double click and run, but you'll still need the JVM in order to interpret the bytecode.
The best way to deploy a Swing based app. to a client's desktop is using Java Web Start.
JWS offers desktop integration - making a desktop shortcut and menu item, each using an icon if specified. The end use can double-click the desktop shortcut cut to launch the app. ( or single-click the menu item to do the same ;).
Best of all, JWS works for all platforms for which the J2SE is supplied. Windows, Ubuntu, Fedora, Solaris, Mac. OS..
For ensuring the user has the correct minimum JRE needed to run the app., use deployJava.js to write the link to the JNLP launch file.
If you export your project in a .jar file, you will be able to run it when you click on it.
I suppose that you know that you must have the virtual machine installed in the computer that runs the program.(The virtual machine is the thing that allows java to be operative system independent)
And also you must know that if you transform that .jar to an .exe file using some kind of gadget... Then java will not be java anymore, because will not be able to run it in non-windows operative systems.
Remember java slogan
'Write once run everywhere"
See this image here i will explain you how to create a .jar using the eclipse IDE:
1-Select your project in the package explorer
2-Select File>Export from the menu
3-Pick Runnable JAR file from the dialog and
4-Click next and follow the rest of the wizard
You can package your application to JAR file. Application in jar file runs on duoble click.
Here is tutorial. http://download.oracle.com/javase/tutorial/deployment/jar/
You can already do this with a normal .jar file if the user has configured the extension to be executed with the JRE. But you can always use something like Launch4J. Please Note this simply wraps the Jar in a EXE file. The file still needs your Dependencies (.jars) and the JRE enviroment.

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?

Categories