Converting a Maven Project to Create a Runnable JAR

See for more information.

In my pom.xml file, I changed build tag to include the “Maven Assembly Plugin”.
Only had to edit the main class value, based on the package and class name.

		<plugins>             <!-- The configuration of maven-assembly-plugin -->
				<version>2.2.2</version>                 <!-- The configuration of the plugin -->
				<configuration>                     <!-- Specifies the configuration file of the assembly plugin -->
			</plugin>             <!-- The configuration of maven-jar-plugin -->
				<version>2.3.1</version>                 <!-- The configuration of the plugin -->
				<configuration>                     <!-- Configuration of the archiver -->
					<archive>                         <!-- Manifest specific configuration -->
						<manifest>                             <!-- Classpath is added to the manifest of the created jar file. -->
							<addClasspath>true</addClasspath>                             <!-- Configures the classpath prefix. This configuration option is used to 
								specify that all needed libraries are found under lib/ directory. -->
							<classpathPrefix>lib/</classpathPrefix>                             <!-- Specifies the main class of the application -->

The main class was from this file:

package com.main;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class SwingApp {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
    private static void createAndShowGUI() {
        System.out.println("Created GUI on EDT? "+
        JFrame f = new JFrame("Swing App");


Then, added the default assembly file, creating a new source folder “src/main/assembly” and adding the “assembly.xml” file (reposted from

	<id>bin</id>     <!-- Generates a zip package containing the needed files -->
	</formats>       <!-- Adds dependencies to zip package under lib directory -->
		<dependencySet>             <!-- Project artifact is not copied under library directory since it is added 
				to the root directory of the zip package. -->
	<fileSets>         <!-- Adds startup scripts to the root directory of zip package. The startup 
			scripts are located to src/main/scripts directory as stated by Maven conventions. -->
		</fileSet>         <!-- adds jar package to the root directory of zip package -->

Then, after issuing ‘mvn package’ from Git Bash command prompt in the same directory as the pom.xml file, it created the target directory with a runnable jar. I double clicked the jar to test.

Help – Install New Software – Copy into field – Add


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s