Jar Package packaged as exe example

Source: Internet
Author: User
Tags xml example

The jar package is packaged as an EXE sample description

For a MAVEN-based Java project, it is usually packaged as a jar,
If you want to package the jar file as an EXE file, you only need to add a plugin to the Pom.xml configuration file.

Here we use launch4j

Environment
    • jdk1.8
    • Maven 3.5.2
Main method

The logic is simple, that is, if the command line has parameters, print the first parameter of the command line,
No parameters print "Hell world!".

package com.hui;/** * Hello world! */publicclass App {    publicstaticvoidmain(String[] args) {        if (null != args && args.length0) {            System.out.println(args[0]);        else {            System.out.println("Hello World!");        }    }}
Pom.xml Example

Just add the following plugins to the build link

<build>        <plugins>            <plugin>                <groupId>Com.akathist.maven.plugins.launch4j</groupId>                <artifactId>Launch4j-maven-plugin</artifactId>                <executions>                    <execution>                        <id>L4j-clui</id>                        <phase>Package</phase>                        <goals><goal>Launch4j</goal></goals>                        <configuration>                            Console                            <outfile>Target/encc.exe</outfile>                            <jar>Target/java2exe-1.0-snapshot.jar</jar>                            <errTitle>Encc</errTitle>                            <classPath>                                <mainClass>Com.hui.App</mainClass>                                <addDependencies>False</addDependencies>                                <preCp>Anything</preCp>                            </classPath>                            <jre>                                <minVersion>1.5.0</minVersion>                            </jre>                            <versionInfo>                                <fileVersion>1.2.3.4</fileVersion>                                <txtFileVersion>TXT file version?</txtFileVersion>                                <fileDescription>A description</fileDescription>                                <copyright>My copyright</copyright>                                <productVersion>4.3.2.1</productVersion>                                <txtProductVersion>TXT product version</txtProductVersion>                                <productName>E-n-c-c</productName>                                <internalName>Ccne</internalName>                                <originalFilename>Original.exe</originalFilename>                            </versionInfo>                        </configuration>                    </execution>                </executions>            </plugin>            <plugin>                <artifactId>Maven-assembly-plugin</artifactId>                <executions>                    <execution>                        <id>Assembly</id>                        <phase>Package</phase>                        <goals><goal>Single</goal></goals>                        <configuration>                            <descriptors>                                <descriptor>Assembly.xml</descriptor>                            </descriptors>                        </configuration>                    </execution>                </executions>            </plugin>        </plugins>    </build>

Create a new Assembly.xml file in the project root directory at the same time

<assemblyxmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"xmlns:xsi="Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/ Assembly-1.1.2.xsd ">    <id>Cdc-upgrade</id>    <formats>        <format>Zip</format>    </formats>    <includeBaseDirectory>False</includeBaseDirectory>    <fileSets>        <fileSet>            <directory>${project.build.directory}</directory>            <outputDirectory>/</outputDirectory>            <includes>                <include>*.exe</include>            </includes>        </fileSet>    </fileSets></assembly>
Packaged

Perform

After packaging, you can see the project target directory generated encc.exe this file

Execute in the directory where the Encc.exe is located

encc aaa

Output results

aaa

Full source

Code

Reference documents

Maven launch4j Plugin

Jar Package packaged as exe example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.