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
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