How do i make a .jar file that will run on any computer with java installed?
like an .exe for C++?
can i do that for Java?
I use JGrasp to compile as a .java file and run as a .class file if that helps at all
How do i make a jar file?
Started by Blmaster, Aug 10 2008 02:21 PM
6 replies to this topic
#1
Posted 10 August 2008 - 02:21 PM
|
|
|
#2
Posted 10 August 2008 - 03:28 PM
Lesson: Packaging Programs in JAR Files (The Java™ Tutorials > Deployment)
I found this page in the Sun docs about compiling to jars. I've never done it before, and I don't have a lot of experience with Java but this should help you. :D
I found this page in the Sun docs about compiling to jars. I've never done it before, and I don't have a lot of experience with Java but this should help you. :D
#3
Posted 10 August 2008 - 03:48 PM
i never done it the real way, but theres inbuilt functions for this in both eclipse and netbeans. heeres the way to do it in eclipse anyway (just import the java files if you dont wanna write it there).
then rightclick chose 'export' --> jar file
then fill in name and be sure to fill in the startup file so it knows where the main method its.
then rightclick chose 'export' --> jar file
then fill in name and be sure to fill in the startup file so it knows where the main method its.
#4
Posted 10 August 2008 - 05:55 PM
Eclipse fatjar does what you need,an excellent plugin to create jar files that i use myself :D
#5
Posted 10 August 2008 - 07:10 PM
i see... thanks for the help. i might just have to download Eclipse and fatjar if that's separate if the tutorial doesn't work that chili game me
thanks guys
EDIT: nvm i got it working on JGrasp.. it has a thing for making jar files. i just didnt see it because you have to make a project and then the option becomes available
thanks guys
EDIT: nvm i got it working on JGrasp.. it has a thing for making jar files. i just didnt see it because you have to make a project and then the option becomes available
Edited by Blmaster, 11 August 2008 - 09:43 AM.
#6
Posted 16 August 2008 - 02:07 PM
I think the best way it's a writting your own Ant script - it's very simple ;) Below I put simple build.xml file which creates the simple jar file in release folder.
<!--
build.xml
Author: navghost
-->
<project name="com.googlepages.navghost.codecall.java.buildjar" default="build" basedir=".">
<property file="${basedir}/ant/ant.properties"/>
<target name="build" depends="jar">
</target>
<target name="compile" depends="build-dir">
<javac srcdir="${src.dir}" destdir="${classes.dir}"/>
</target>
<target name="jar" depends="compile">
<jar destfile="${release.dir}/simple.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Built-By" value="navghost"/>
<attribute name="Main-Class" value="com.googlepages.navghost.codecall.java.buildjar.Main"/>
</manifest>
</jar>
</target>
<target name="build-dir">
<mkdir dir="${release.dir}"/>
<mkdir dir="${classes.dir}"/>
</target>
<target name="clean">
<delete dir="${release.dir}"/>
<delete dir="${classes.dir}"/>
</target>
</project>
"Work should be challenging and the challenge should be fun. Great just isn't good enough!"
#7
Posted 16 August 2008 - 02:55 PM
There are a couple of ways.
The way I use the most is in eclipse, I export my project as a jar file, and instead of oking it, I click next twice and select the starter. This way any computer with the jre will run the program with a simple double click. I use this for all of my Java based IRC bots.
There is also a program that converts jars into exe programs or executable linux programs. These are called Java Native Compilers, and I find that they save half the memory if not more, making the application faster. The one I use is: JavaNativeCompiler Its free and advertisement free for linux, for windows, it will display a quick ad until you buy it. There also are other programs that do this.
The way I use the most is in eclipse, I export my project as a jar file, and instead of oking it, I click next twice and select the starter. This way any computer with the jre will run the program with a simple double click. I use this for all of my Java based IRC bots.
There is also a program that converts jars into exe programs or executable linux programs. These are called Java Native Compilers, and I find that they save half the memory if not more, making the application faster. The one I use is: JavaNativeCompiler Its free and advertisement free for linux, for windows, it will display a quick ad until you buy it. There also are other programs that do this.


Sign In
Create Account


Back to top









