.exe from launch4j works, but not on all computers - java

I wrap my Java project's JAR file to an .exe file using launch4j, which works fine on my dev machines and several other computers. However, one user reported he cannot run the .exe file on his machine, as a popup message tells him
Could not find the main class.
Interestingly, the user is able to run the JAR file directly on the same computer, either by calling it via java -jar from command line, or directly by double-clicking the JAR file in the Windows explorer (or via shortcut). That user has installed latest JRE.
I have seen on other threads here that this problem could occur because of invalid Manifest files, e.g. if the main class is missing there. However, I think this is not the case, because it's working fine if the JAR is called directly as said.
So I assume the problem is somewhere with my launch4j configuration. There I have not specified a custom Manifest file, only the input JAR file and the output .exe file.
I thought my launch4j config would be fine, because the .exe is running on several machines using different Windows versions. This is the first time I encounter that problem, but as said with the .exe file only.
Any ideas?

We just found the problem with that one client machine. It had the 64 bit version of the JRE installed, that was causing the problem. After replacing it with the 32 bit JRE version the .exe file can be correctly started again.

Yes,even I faced this problem. I used jar2Exe instead of launch4j. It's working fine.You better use 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.

Windows, run JAR with double click

I'm experimenting with Java for the first time.
I'm using Intellij IDEA and creating a simple app.
In the IDE it's working fine, then I create a JAR artifact and run it like this:
java -jar myappname.jar with no problem.
Now I would like to start the same JAR with double-clicking it from explorer but nothing happens, why?
Please note that if I double click another JAR (sikulixsetup-1.1.3.jar) it starts correctly and show the gui, so the problem is not type association in windows.
My test app does not have a gui but I know if it runs correctly because it's automating windows using Sikulixapi library, so I see if it's doing something or not.
thanks!
Ok, I solved my issue.
Usually the JAR runs without any problem by simply double clicking it in windows,
in my case it was not running becase the .jar files was associated to the 32bit version of javaw.exe while the code in the JAR was expecting the 64bit environment.
Changing the .jar type association in windows from 32bit to 64bit version of javaw.exe solved the issue
Its because jar is not executable binary but plain zip archive. OS cannot execute that. That is why you must use java executable and pass archive as argument to run your application.
If you want your app to be "clickable" you must use some wrapper solution like http://launch4j.sourceforge.net/
Change the default program to use while opening the file from one Java to the other (32 to 64 bit or vice-versa).

Jbrowserdriver within jar bundled as exe won't work

I am working on a program for Windows and Mac. This program is using the Jbrowserdriver and Selenium libraries to access different websites and the websites' various "inputs" like buttons and text fields.
An example of the use can be seen here below:
JBrowserDriver driver = new JBrowserDriver(Settings.builder().
timezone(Timezone.AMERICA_NEWYORK).build());
driver.get("http://website.com/example.php");
String webString = driver.findElement(By.id("divContainer")).getText();
System.out.println(webString);
Now here comes the issue, I have three different files:
The jar compiled into a Mac .app,
The regular .jar file,
The jar compiled into a Windows .exe file.
When running the Mac .app, it works with no issues at all. When running the .jar file on Mac there is no issue, and it works entirely. When running the .jar file on a Windows computer, there are no issues either, and it works as supposed. But whenever I run the .exe file on a Windows machine it opens the program, but at the function where I click a button, and it runs a JBrowserDriver function it "stalls" so to speak, it doesn't do anything at all.
This to me seems as if it is the JBrowserDriver which is the issue, but how come it works when just running it as a regular .jar but not when compiled into the .exe file? Am I missing something, or is this just not possible to do?

Convert jar to exe

I try to convert a jar file to an exe file.
I followed the instructions provided here using launch4j .
I get only an XML file but no exe as expected.
Any ideas?
So how should I deploy my application?
Your user would have to have the JRE installed on their computer. However, you could also distribute java.exe and rt.jar (the java run time jar) as well as any library jars you need for your application along with your program. Since the java command has an optional classpath parameter you could write a batch file (something like runme.bat) which would look something like this:
java -cp rt.jar;myapplication.jar;otherjars.jar MyMainClass
This is still Windows specific because the java.exe file would be a Windows specific file. You could also add in logic to check for the environment variable JAVA_HOME and if that's set on the user's computer then the java program specific to their OS would be in JAVA_HOME/bin
Your real problem comes when you're not sure what operating system your user will be using AND you don't know if they have Java installed. If you simply require that the user has the Java Runtime Environment installed then you're problem is solved for all users.
I hope that helps.
Greg

How to run a java executable file on other computer

I made a small application using Java Swings and then created a jar file of the project using 'clean and build' option in Netbeans. Then, I converted that .jar file in a .exe file using the software 'Launch4j' and it was perfectly running on my laptop. However when I tried running that exe file on other laptop. It displayed the error: Class NewJframe.firstfile couldnot be found.
( I made the database on the other laptop also with MySql Connection).
Please help me clarify why I am getting this error.
Also, I would like to know what all are the requirements to run an .exe file on other computer which I made from a .jar file?
I would pretty much expect something like Launch4j to take care of all your packaging requirements; did it give you options to "include all dependencies" that you didn't click "YES" to...?
It sounds like it's packaged your app, but possibly not the Java runtime envt it needs to run your app.
Try giving him the JAR file and see if he can run that. If he can, It's a problem with Launch4j, if he can't it's a problem with Java.
Alternatively try something like Excelsior JET instead.
Class NewJframe.firstfile couldnot be found
Launch4J only bundles your application's main JAR file inside the .exe (or not even that if you select "don't wrap JAR") - any other JARs that the main one depends on must be present in the same relative locations, you can't necessarily copy just the .exe.

Categories