How to run a java executable file on other computer - java

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.

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.

Generating executable file in IntelliJ for Windows

I used to work on an IntelliJ project that was started before I started working on it. This project had a configuration that allowed me to generate an EXE file that could easily be sent to windows users.
It would generate a massive EXE file bundled with all the needed JARs of the application, and upon running it the first time, it would silently "install" itself into the AppData folder, as if it were a regular windows setup file, even though the user would not even notice it doing that installation.
I am trying to configure a project in IntelliJ to do the exact same thing, but first I have not been able to output the exe file by selecting "exe" as the Java FX native bundle type. It just generates a .jnlp and .jar file. When I select "all", as per some other post here in stackoverflow, it generates an exe file, but only with a few kb in size, which does not contain any of the .jar files that should be part of it. Moreover, when I try to open it, it just crashes saying the main class was not found.
Am I missing some setting for building the project? I am using IntelliJ 2018.3.2
Here are some screenshots:
I have been able to get past this error, after changing the verbosity of the compilation and going through the logs.
There was a log message which helped fixing this:
The process complained about the Inno Setup Compiler missing, which was right. Makes me wonder why IntelliJ would have that feature built in if it depends on external tools but does not notify the user clearly of this.
Detected [iscc.exe] version 0.0 but version 5.0 is required.
After going to the Inno Setup site, downloading and installing the tool, I was able to get the executable to be generated.
Now I am struggling with another error, which is the executable complaining about the main class referenced in the Artifact not being found, but at least I have moved past the first problem! Going to tackle this one now...
The best solution for this is using exe generator software.
There is plenty of exe generators out there.
EXE4J is the most simple & easy tool to use.
In EXE4J,
You can upload your main jar file and select the main class.
I think this will be solved your problem.
This may be due to you`ve extracted Jars to your output root, while you neet to Put it(you can check difference by deleting everything from your output root in Output Layout screen and then just right click on jar on the right side, you will see two options here, try another one

Package java application without needing to modify PATH

I have a Java console application which I can package into a jar file using IntelliJ, and can run the program with a bat or cmd file which has the following command:
java -jar main.jar
The problem with this is that my development machine (Windows) has the JAVA_HOME and PATH modified so that this works without issue.
Is there a way so that I can package the jar so that it can be opened without needing to modify the PATH?
I've tried looking all over and found questions on SO and other sites relating to building the jar, but it seems like all of these still require modifying the PATH variable.
Java's documentation says:
Making changes to the system PATH variable is not typically necessary for computers running Windows or Mac OS X. The instructions below are intended for advanced users or system administrators only.
If this is the case then how can others run the program if they are not an "advanced user" or "system administrator"?
Edit:
As an aside, I know this is possible because some jar files, like those which use the Swing framework are able to be run by just double-clicking on the jar and then the application opens.
Edit 2:
This article seems to be along the right path.
Edit 3:
This is kinda what I was looking for, however, it didn't work for me. The command I was trying on my existing jar was jar uvfm main.jar manifest.txt which returned updated manifest, but changed nothing.
No you cannot. They are system variables. The best thing to do is to write a shell script that will set these variables.
no. It should be able to understand 'java' command. For this path need to be set. But if you are planning to shift your jar as an application, you need to ship jre as well with your application. But i dont think this is what you want

Taking an eclipse java project and packing it into a jar?

Right now i've written a simple SWT application using eclipse, and I want to pack it into an executable .jar file so I can give it out to friends and such. But I have the following problems:
-Right now i'm reading files by using their filename in the program, and putting them in the root folder of the eclipse project. That works fine for running in eclipse, but when I export to jar they're not in the jar. Is there a way to put them in the jar and access them in the code?
-I also need the SWT .jar dependencies or whatever its called(the files you need for SWT).
Does anyone know how to do this?
Take a look at ClassLoader.getResourceAsStream() API.
All you need to do is include these files in the with the source code of your project, then to have access to then have a look at this link

Distributing a Java console program

I have created a Java console application using Netbeans. In the Netbeans dist directory I have the class file of the project. Now I need to give the executable files to someone else
who will run them on another PC.
Which file I should send? How can he run them on his PC? Is there any way to create an exe type file?
Both PCs have the JDK installed.
Build a jar file with a main class specified in it.
If he has Java installed and .jar is associated with that, he should be able to just double-click on it.
Alternatively from a command line he'd be able to run:
java -jar program.jar
There are programs around to create executable wrappers around this, but a jar file is a simpler solution in terms of packaging - it's worth trying that to start with.
In additon to Jons answer:
If you have a runnable jar to start with, it is frequently much easier to package it up in an EXE file. If you have the need search Stackoverflow for JSmooth and one-jar.
NetBeans actually answers your question. If I do a Clean/Build, the output says:
To run this application from the command line without Ant, try:
java -jar "insert_your_project_name_here.jar"
theres a handy page about this here:
java tools tutorial
It describes creating jar files a little further down the page
You can go to run menu and select clean and build project or shift+f11 after this go to dist folder in project folder and use .jar file and run that by hint say in over .

Categories