Jump to content

How do i make a jar file?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
Blmaster

Blmaster

    Learning Programmer

  • Members
  • PipPipPip
  • 50 posts
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

#2
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
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

#3
acwclassic

acwclassic

    Newbie

  • Members
  • PipPip
  • 25 posts
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.

#4
Arkie

Arkie

    Learning Programmer

  • Members
  • PipPipPip
  • 92 posts
Eclipse fatjar does what you need,an excellent plugin to create jar files that i use myself :D

#5
Blmaster

Blmaster

    Learning Programmer

  • Members
  • PipPipPip
  • 50 posts
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

Edited by Blmaster, 11 August 2008 - 09:43 AM.


#6
navghost

navghost

    Newbie

  • Members
  • PipPip
  • 17 posts
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
morefood2001

morefood2001

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,720 posts
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.