Unable to run java application (exe) converted using launch4j - java

I converted a java program (Number Guessing Game) to .jar but it did not run on double clicking so,ran it on cmd (it worked) now i converted it to .exe using launch4j but the application does not work either . Help!

Open your jar file with one zip application (ex winrar)
go to META-INF folder and open the file MAINIFEST.MF
put your main class there as follows
Main-Class: your-packaging.YourMainClass
save this file and try to create your exe file again
This will make your jar runnable, therefore when you create an exe file using Launch4J, your application will execute once you double click on that
If in any case your application did not run again, you have
dependency problem. for solving that you should also add Class-Path: within your MANIFEST.MF file!

Related

Selenium-extract WebDriver from jar for execution

I have a selenium program that is intended to be copied onto other computers before execution. I would like to only have to ship out a runnable jar. On execution the program should extract chromdriver.exe to a new directory in the directory from which the program was executed. The .exe should only be exported if it does not already exist in that exact location. Assuming I do already know the .exe is not there, how do I program the application to extract the .exe File? The resource folder has been added to the class path under sources (I am using eclipse) so the .exe does appear in the jar when I export the project. Now I just need to see how to extract it on execution
Thanks!
I assume that your chromedriver.exe file is contained in your jar file in a package named res. The following code will extract the file to your local harddrive.
InputStream i = this.getClass().getResourceAsStream("/res/chromedriver.exe");
Files.copy(i, new File("c:\\target\\chromedriver.exe").toPath());
You can add a CopyOption if you like.

Cross Deploying Java

I have a java project which consists on 3 classes(Program,Proxy,Events) from which Program has the main function on it.
I have a Properties file in the same level as src folder.
I want to deploy this project so that i can run it in a cronjob on a ubuntu server but i have no idea how to do so.
1- How do i deploy it? i can only see 3 .class in the bin folder, i thought i would get only 1 output file of some sort.
2- Where do i put my settings file when deployed?
Using Eclipse BTW
From the directory, in a terminal, run java Program to run your application. You'll want your settings file in the same directory (depending on how you are loading it in your code, but if you are loading it as a classpath resource, that would be the spot to put it).
Alternatively, if you want to have a single file, in eclipse, you can export your code to a JAR file:
File > Export > Java > Runnable Jar File
Pick your project
Choose a filename for the JAR (usually ending in the .jar extension)
On the last page of the wizard, choose Program as your main class
To run it, enter java -jar XYZ.jar where XYZ.jar is what you named it.

Converting to jar or exe

I have around 10 java files with their corresponding class files. The whole application works when i execute one of the main class. I execute it using cmd. I need help converting it into a single self executing file. eg: exe or jar
A jar file is little more than just a zip of all classes and resource files. You need to add details into META-INF/MANIFEST.MF file so that the class containing the main method to be executed is know.
This should help: Link
You can try invoking the jar file as follows:
java -cp <jarfile.jar> <Complete.Package.ClassNameWithMainMethod>
You can make jar by Exporting the project using following methods in Eclipse IDE
File->Export->Java->JAR.
Note: This is already have a solution to change to exe or JAR.
How can I convert a .jar to an .exe?

Creation of a .bat file of a java application

I am a bit confused about the process to create a .bat file of a java application. I have exported the executable jar using IDE say Application.jar in C: directory. Then I have written two lines in a .txt file as stated below and saved it as .bat file in the same directory where i have my application.jar. But on double click of the .bat file, the application is not getting executed.
.BAT file code
javac Application.java
java -cp . Application
Note: I have also set the JRE and JDK path in my environment variables till bin path in My Computer properties. But it is not working. Can someone suggest me how can I fix this, because I want to execute my code by doubleclickng on a .bat file. It will be nice if someone can provide me every step I need to follow to accomplish this as I havent ever done this before.
Thanks ,
The first line in your batch file is attempting to compile your program !?
The second line is attempting to run the Application.class file.
What you want if you have produced an executable jar file is:
java -jar Application.jar
But you don't really need the batch file at all. If you double click on the jar file and it runs your program then you can just create a shortcut to it.
Your .bat is just fine. When you double click it might be executing and then closes. This is because your program might not have any UI and it isnt waiting for any input. To verify this take a command prompt and then execute your bat file via that.
In other case I assume that you have a java class called Application and you need to run this via a batch file. In that case if the class have a main method then you just need one line in .bat file
java -cp <the path to class file> Application
So you might be using a javac just to take advantage of class path as current directory. So when you say
javac Application.java
java -cp . Application
It compiles the class to current folder and set that as class path and then execute. This is absolutely file as long as the Application.java doesnt have any third party dependency. But in this case again you need not set -cp to . (current directory will be taken as classpath automatically unless otherwise specificed). So below will also work fine.
javac Application.java
java Application
I support Jurgen reply. If you have an executable jar file and a jre in path then double clicking it will run the application. The META-INF folder inside the jar will have a MANIFEST.MF file which uses a property called Main-Class: to specify the main executing class. And on double clicking this class gets executed. However its only useful if you have a UI. Else it'll also have no effect.
In all these context the Application.jar you mentioned is irrelevant. If that is a third party jar that you need to run the you should include that in -cp argument.

making .exe file for java project containing sqlite

I want to create .exe file for my java project and give it to my friend. I wrote my project in eclipse and it uses sqlite. I don't know how to make a .exe file that can be run in other PCs.
Can any one help?
P.S:I saw this link but it is not useful for me!
Create .jar of an eclipse project that uses Sqlite DB
.exe is a creature of Windows.
To run a Java program, you typically:
Create a .jar file (the "native" Java library format)
Write a DOS/Windows .bat file (or, equivalently, Linux shell script) to run your Java program (using the Java .jar file)
Optionally, create some easy-to-use mechanism for the end user to download the Java JRE (if it's not already installed on their PC).
Your .bat file can be as simple as this:
start javaw -jar myjarfile.jar
Have you considered creating Runnable jar from eclipse.
In eclipse, go to File > Export > Java > Runnable Jar.
There you ll find some options and you can use what suits you. The jar created should be able to run all by itself (obviously it needs the java run time).
Try this out.
I would recommend using a bat file. You can make a double clickable jar file, but I feel that is sometimes restrictive and not intuitive.
Not many end-users know that a jar file is double clickable.
You need to make sure the jar file has a main class and classpath defined. The classpath section in the jar file sometimes causes issues. Like you cannot reference a file or path on the file system. Only files or folders that can be relatively referenced from the location of the jar file.
For windows users, you cannot easily make an exe file from a jar file. There are methods like using jsmooth, that will wrap your jar file into an exe file (bloating the exe file in the process).
The easiest way is to create a bat file. You can easily convert a bat file into an exe and make the exe file have an icon and everything. Link to a converter here:
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html
First create an executable jar file by clicking on File menu, then export, and then select runnable jar file.
Then select main class and click ok - the jar file will be created.
After that use Launch4j application to create .exe. Launch4j is the best option for creating an exe file.
Then use Inno Setup Creater to create an installer and it is done.

Categories