Java - Jar (Startable|Runnable|Executable)

Java Conceptuel Diagram


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



You start it with the following command:

java -jar myStartableJar.jar



Eclipse Export Runnable Jar 1

Eclipse Export Runnable Jar

and you get also an ant script


ant script

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

		Build a startable Jar

	<!-- 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 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 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}/${}-${DSTAMP}.jar" filesetmanifest="mergewithoutmain">
				<attribute name="Main-Class" value="com.gerardnico.myMainClass" />
				<attribute name="Class-Path" value="." />
			<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" />

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



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 ...
Eclipse Export Runnable Jar 1
Java - Jar (Startable|Runnable|Executable)

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 You start it with the following command: ...
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