I have made a runnable .jar file. I want to run it on a PC which does not have jdk instilled, Can I add jdk in .jar file itself and run it ?
Suppose that your have installed your Java in the following path:
1 - copy this jre folder
C:\Program Files\Java\jdk1.7.0_25\jre
now all you need is to create a .bat text file with the following content:
#echo off
jre\bin\java -jar your_filename.jar
2 - name it as run.bat
that's all you need.
To wrap up things, the directory structure should be:
|---jre
|---bin
|---... // other files and folders
|---run.bat
|---your_filename.jar
click or create shortcut from run.bat and that's it.
If you are more interested in having a stand-alone executable file, then take a look at Launch4j (google it :) )
You don't need the JDK for it to run, just the JRE (Java Runtime Environment). You can download the JRE from here.
This is, unfortunately for you, something that will be needed to execute your code.
Related
I would like to bundle a jre folder into my generated launch4j .exe file via maven pom.xml (For some reason, I don't want an installer, just a click to run Java application that has its own embedded jre). Is it possible? I have read through several posts and I don't get a maven automated one. I don't want to do it the manual way, just by packaging through maven because of some reasons
I've tried bundling a jre folder into an exe file via maven but it ends up not running after I uninstall java from my system or after I remove the jre folder from which the pom.xml Launch4j configuration was using . Kindly assist.
Update: I found a perfect tool for just the above task, Warp-Packer. The software just requires a few CMD commands/terminal commands to compress and add your JRE and pre-generated executable(from software like Launch4j or any of your preference) to one .EXE file which requires no installation. Click to run.
Basically, it is a simple command like:
cd %jre_folder% - %jre_folder% is the path to your folder where the warp-packer.exe, JRE and pre-generated exe(in my case myapp.exe) file are.
then type the following:
.\warp-`packer` --arch windows-x64 --input_dir jre_folder --exec myapp.exe --output myapp.exe
The image below illustrates that
I'm looking to make a jar file out some Java code using jar [options] [name] [files] from the command line but it's not recognized.
According to Oracle Jar is part of the JDK. I have both 7 and 8 installed. How do I run the jar function?
I don't have a C:/Java that the Oracle documents show. I've tried running jar from within the JDK directories and with admin rights.
I'm not putting params in yet, want to check I can at least find the jar function first.
Running jar from JDK directory(1.8) http://puu.sh/eoer7/4fcd0ce63c.png
Running jar from System32 http://puu.sh/eoe3X/076d79b4e4.png
You have displayed two installations of the Java Runtime Environment (or JRE). You need to install a Java Developer Kit (or JDK), to get jar. Set your JAVA_HOME to the installation directory of the JDK, and add it to your PATH.
set "PATH=%PATH%;%JAVA_HOME%\bin"
Also, Using JAR Files: The Basics says (in part) JAR files are packaged with the ZIP file format, and you can use tools that can read and write ZIP files to work with them.
Can any one please suggest me that how can I create .exe wrapper to install my Java application.
Currently Iam using the following command to install my application.
"java -jar application.jar"
After googling I came to know that we can create .exe by using some third party tool which is open source.
But don't know exactly which is best for my requirement. I have only application.jar with me as an input.
Thanks In Advance.
In order to make the command double-clickable, you have two options.
The first is a bat file with exactly that string "java -jar application.jar" in it, which is double-clickable just like exe.
The second is to make an exe by compiling the following C program.
int main(){
system("java -jar application.jar");
}
I like to use 7zsd.sfx to create installers for my java applications.
Directions:
1.) install 7zsd.sfx from http://7zsfx.info/en/ and install 7z
2.) create a .7z archive
3.) add all the jre files required to run the java application to the archive
4.) add the application itself to the archive
5.) add a .bat or .exe file (for windows) to install the files after 7zsd.sfx extracts all the files
6.) add a .bat or .exe file to run the java application using the jre files
7.) create a file (preferably named "app.tag") with a structure such as that below (add your own parameters)
;!#Install#!UTF-8!
Title="My App"
BeginPrompt="Do you want to install My App?"
Progress="yes"
ExtractDialogText="Please wait while app files are being extracted..."
GUIFlags="32"
ExtractTitle="Installation"
FinishMessage="My app has been installed and added to your desktop."
RunProgram="setup.bat"
;!#InstallEnd#!
The RunProgram is the program that runs after the files are extracted to a temporary folder. This program should create a permanent folder to hold the necessary extracted files (jre, java application, and executable to run app with jre). Additionally, the program should create a nice, good-looking shortcut for the executable file used to run the app and it should move it to the desktop and add an icon.
Finally, to create the exe which will install your files, go to the command line and access the folder with 7zsd.sfx and type in the following command:
copy /b 7zSD.sfx + [pathToDirectory]\app.tag + [pathToDirectory]\yourAppArchive.7z [pathToDirectory]myExeInstaller.exe
I have been researching this for weeks and can't seem to get it figured out.
I have a Java program that I have written using NetBeans. It has several imports or .jar files it relies on. It runs fine in NetBeans. But I can't figure out how to call the .jar files and compile from the bash command line. I am using a Mac. I have read several posts on this and none so far have made sense to me. There are 26 imports being used in the program. I don't know if I need to use Ant or specify -CP or Classpath to compile. Surely I don't have to type each one of the .jar files out to compile this from the bash command line?
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
You should be able to simply use ant with the build.xml in the Netbeans project directory. It should "just work" for you. The project will likely not build WITHOUT Netbeans installed (if you tried moving the project to a different machine, for example), but with Netbeans, it should work out of the box.
If you don't have Ant installed, you'll need to install it.
Addenda:
To build it, if you have Ant installed, you should be able to simply go the project directory, where the build.xml file is, and type "ant", and it should build and put stuff in the dist directory.
If you go in to the dist directory and type java -jar yourapp.jar, it should run, because the manifest in the jar will point to the nearby lib jar files. If you want to distribute the app, there are different options for java, such as making a Mac compatible application, or a Windows EXE, you'll need to search for those. Or you can simply distribute the contents of the dist directory and write a script to do that whole java -jar yourapp.jar command.
If you are using Java 1.6 or above, you can toss all 26 jar files into a folder and simply add
-cp folder_name/*
as your classpath argument.
Some other options are 1.) type all 26 jar files on the command line (using the -cp argument as you have mentioned) 2.) use Ant or Maven or some other build tool and list those 26 jar files in the config file for said build tool or 3.) write a quick-and-dirty shell script that will set the CLASSPATH environment variable for you and then run your javac command.
How do I run a .jar executable java file from outside NetBeans IDE? (Windows Vista). My project has a .jar file created by Netbeans. We'd like to run it. Either: how do we run the file or how do we create a 'proper' executable file in NetBeans 6.1?
Running a jar is as simple as
java -jar filename.jar
as Laplie said, java -jar your.jar
EXECUTABLE file : see this thread for answers How can I convert my Java program to an .exe file?
One of the best technique to run the jar file or jar jar file
Create the jar file by jar command choose your jar filename
Java_Jar_File.jar
Run the jar file us the command like java -jar Java_Jar_File.jar
You can do it from the command prompt if java isn't in your path by finding the full path to your java install, something like:
C:\java\java.exe -jar C:\jar_you_want_to_run.jar
or if java is in your path:
java.exe -jar jar_you_want_to_run.jar
This will run the jar produced by netbeans.
First, make sure you set the Main Class in your NetBeans project properties dialog.
Then, you can either
Double-click the jar file (This should work on any machine with an installed JRE)
or
Make sure that java.exe is in the path (or replace java below with the fullpath and file name of the executable), put the following in a batch file:
java -jar filename.jar
Then you can double-click the batch file instead of the jar (useful if you have people unaccustomed to using naked jar files)
OR
You can go down the path described here How can I convert my Java program to an .exe file? to build a .exe for windows.
Make a BAT file with
java -jar filepath.jar
from a command prompt you can run this command: java -jar your_jar.jar.
To run a java jar file its file association should be properly configured. There is a free tool called jarfix to fix all jar file association problems. Run this file to fix all jar issues.
In the project properties dialog in NetBeans you need to set the Main Class - otherwise the generated .jar will not be executable. Then, as already indicated, either double clicking on the .jar or the command java -jar will start the program.
If you have problems with running your jar, make sure you are trying to run your current version to get newest version in Netbeans: GoTo Run Menu --> Clean and build