Java - Jar (Startable|Runnable|Executable)

Java Conceptuel Diagram

About

A (Startable|Runnable|Executable) jar-file is an jar archive of compiled classes that contains a manifest-file that point to the (start|main) class

Management

Execution

You start it with the following command:

java -jar myStartableJar.jar

Creation

Eclipse

Eclipse Export Runnable Jar 1

Eclipse Export Runnable Jar

and you get also an ant script

Ant

ant script

<?xml version="1.0" encoding="UTF-8"?>
<project name="My Project" default="dist" basedir=".">

	<description>
		Build a startable Jar
	</description>

	<!-- set global properties for this build -->
	<property name="src" location="src" />
	<property name="build.class.dir" location="classes" />
	<property name="build.jar.dir" location="dist" />

	<target name="init">

		<!-- Create the time stamp -->
		<tstamp />
		<!-- Create the build directory structure used by compile -->
		<mkdir dir="${build.class.dir}" />
		<mkdir dir="${build.jar.dir}" />

	</target>

	<target name="compile" depends="init" description="compile the source ">

		<!-- Compile the java code from ${src} into ${build.class.dir} -->
		<javac srcdir="${src}" destdir="${build.class.dir}" />

	</target>

	<target name="dist" depends="compile" description="generate the distribution">

		<!-- Create the distribution directory -->
		<mkdir dir="${build.jar.dir}" />

		<!-- Put everything in ${build.class.dir} into the MyProject-${DSTAMP}.jar file -->
		<jar destfile="${build.jar.dir}/${ant.project.name}-${DSTAMP}.jar" filesetmanifest="mergewithoutmain">
			<manifest>
				<attribute name="Main-Class" value="com.gerardnico.myMainClass" />
				<attribute name="Class-Path" value="." />
			</manifest>
			<fileset dir="${build.class.dir}" />
                        <!-- External jar if needed -->
			<zipfileset excludes="META-INF/*.SF" src="lib/javamail-1.4.5/mail.jar" />
			<zipfileset excludes="META-INF/*.SF" src="lib/jaf-1.1.1/activation.jar" />
		</jar>
	</target>

	<target name="clean" description="clean up">
		<!-- Delete the ${build} and ${dist} directory trees -->
		<delete dir="${build.class.dir}" />
		<delete dir="${build.jar.dir}" />
	</target>

</project>

Support

Error: Could not find or load main class myJar.jar

Error: Could not find or load main class myJar.jar

To be able to start a executable jar, use this command:

java -jar myJar.jar

and not

java myJar.jar





Discover More
Java Conceptuel Diagram
How to distribute your (Desktop) Java application to your users ?

An article that 1001 ways to bring your application to your users. This page talks especially over Desktop and Command application because Web Application Packaing is dependent of your web framework ?...
Java Conceptuel Diagram
Java - (Jar|Java ARchive) File

JAR stands for Java ARchive and is file format born in 1996 as a simple extension of the popular ZIP archive format with class and other required resource files: manifest signature files images,...
Eclipse Main Class
Java - (Main|Start) Class

in Java is called a Main class. The (Main|Start) class is a class that: have a main method will start the main thread (process) main classjar You can start the java application by: calling...
Java Conceptuel Diagram
Java - Application

An application in shipped in an archive format with a main class that contains a main method that starts the application. instancejava/lang/Runtimeclass RuntimeOperating System environment ...
Java Conceptuel Diagram
Java - What is the Classpath?

Java classes needed to execute a Java program can be physically located in different file system directories. When Java classes are loaded, it searches a list of directories that are specified in what's...
Card Puncher Data Processing
Maven - Shading

Shading is performed by the Apache Maven Shade plugin. Shading = Relocation of the class to avoid a JAR hell Shading i.e. rename - the...
Java Conceptuel Diagram
Vert.x - Fat Jar with Vertx Launcher

How to create a fat jar that wraps the vert.x launcher or a custom launcher to be able to use its commands With the launcher as the main class in a fat jar, Once the launcher is wrapped, you can...
Java Conceptuel Diagram
Vert.x - Main Method

A Main method is one of the two start point of a Vert.x application. verticle Create a application script or a runnable jar. Example with the gradle application plugin ...



Share this page:
Follow us:
Task Runner