In diesem Artikel wird die Methode zur Verwendung von Maven zur Generierung von ausführbaren JAR -Paketen vorgestellt. Es wird mit Ihnen geteilt. Die Details sind wie folgt:
Aus dem XSI von POM können Sie das Schema öffnen, das POM beschreibt:
Sie können die Struktur des Projekts im POM sehen:
Das von der Standard-MVN-Installation generierte Glas hat nicht den Haupteintrag der Klasse, und die Hauptklasse muss in Maven-Compile-Plugin festgelegt werden.
<project xmlns = "http://maven.apache.org/pom/4.0.0" xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance http://maven.apache.org/xsd/maven-4.0.0.xsd "> <modelVersion> 4.0.0 </modelversion> <gruppe> com.cetc.di </gruppeId> <artifactid> hellocetc </artifactid> <version> <version> 0.0.1-snapshot> </artifactid> 0.0.1-snapshot> </fusioning> </susion> 0.0.1-snapshots </fusion> </artifactId> <version> 0.0.1-snapshot> </saktaging> jar </Version> 0.0.1-snapshot <name>hellocetc</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build><pluginManagement><plugins><plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <archiv> <ifest> <Annclass> com.cetc.di.hellocetc.app </machclass> <addClASSPath> true </addClASSPATH> <classPathprefix> lib/</classPathPrefix> </Manifest> </archiv> <classesDirectory> </classSdirectory> </Manifest> </</bloße> </classSDirectory> </& sub2;/</</</ukesdirectors </pluginmanagement> </build> </project>
MVN Installation ausführen:
Im Zielverzeichnis wird festgestellt, dass das JAR -Paket generiert wurde:
Mit Java Decompiler können Sie sehen, dass die Mainclass zum Manifest hinzugefügt wurde:
Verwenden Sie MVN-Hilfe: Effektiv-POM, um die vollständige Struktur von pom.xml (einschließlich ererbter Eigenschaften) anzuzeigen:
[Info] nach Projekten scannen ... [Info] [Info] --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- angewendet: <!- =================================================================== =================================================================== =================================================================== =================================================================== =================================================================== =================================================================== =================================================================== ====================================================================== =================================================================== ====================================================================== ====================================================================== ====================================================================== ====================================================================== ====================================================================== ====================================================================== ====================================================================== ==============================================ieben xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance" xsi: scheMalocation = "http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven- <modelVersion> 4.0.0 </modelversion> <gruppe> com.cetc.di </GroupID> <artifactId> hellocetc </artifactid> <version> 0.0.1-Snapshot </Version> <name> HelloCetc </name> <url> http://maven.apache.org </name> <url> http://maven.apache.apache <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <repositories> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Central Repository</name> <url>https://repo.maven.apache.org/maven2</url> </repository> </repository> </repository> </repository> <pluginRepository> <pluginRepository> <releases> <UpdupingPolicy> nie </updatePolicy> </releases> <snapshots> <enabled> false </enabled> </snapshots> <id> zentral </id> <name> central repository </name> <url> https </pluginRepository> <build> <sourceDirectory>D:/Users/a/Workspaces/MyEclipse 2015/hellocetc/src/main/java</sourceDirectory> <scriptSourceDirectory>D:/Users/a/Workspaces/MyEclipse 2015/hellocetc/src/main/scripts</scriptSourceDirectory> <TestSourcedirectory> d:/user/a/Workpaces/MyeClipse 2015/HelloCetc/src/test/java </testSourcedirectory> <outputDirectory> d:/user/a/workspaces/myeclipse 2015/hellocetc/target/clases </optimalDirectory> <testOutputDirectory>D:/Users/a/Workspaces/MyEclipse 2015/hellocetc/target/test-classes</testOutputDirectory> <resources> <resource> <directory>D:/Users/a/Workspaces/MyEclipse 2015/hellocetc/src/main/resources</directory> </resources> </resources> <testResources> <testResources> <Directory> d:/user/a/wortspaces/myeclipse 2015/hellocetc/src/test/ressourcen </direcessory> </testResources> </testResources> <Direcidory> d:/user/azername> hellocetcetcetc/actocethot </dirrence </azername> hellocetcetc-0.0.0.0.0.0.0.0.0.1-SnapShoth. <pluginManagement> <plugins> <artifactId>maven-antrun-plugin</artifactId> <version>1.3</version> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2-beta-5</version> </plugin> <plugin> <artifactId>maven-dependency-plugin</artifactId> <version>2.8</version> </plugin> <plugin> <artifactId>maven-release-plugin</artifactId> <version>2.3.2</version> </plugin> <plugin> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <source>1.8</source> <target>1.8</target> <archive> <manifest> <mainClass>com.cetc.di.hellocetc.App</mainClass> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> </manifest> </archive> <classesDirectory /> </configuration> </plugin> </plugins> </plugins> </pluginManagement> <plugins> <artifactId>maven-clean-plugin</artifactId> <version>2.5</version> <executions> <execution> <id>default-clean</id> <phase>clean</phase> <goals> <goal>clean</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>default-testResources</id> <phase>process-test-resources</phase> <goals> <goal>testResources</goal> </goals> </execution> <execution> <id>default-resources</id> </goals> </execution> <execution> <id>default-resources</id> <phase>process-resources</phase> <goals> <goal>resources</goal> </execution> </plugin> <plugin> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <executions> <execution> <id>default-jar</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> <configuration> <source>1.8</source> <target>1.8</target> <archive> <manifest> <mainClass>com.cetc.di.hellocetc.App</mainClass> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> </manifest> </archiv> <clasesDirectory/> </configuration> </execution> </executions> <configuration> <quelle> 1.8 </source> <target> 1.8 </target> <archiv> <ifest> <Angsclass> com.cetc.di.hellocetc.app </Mainclass> <add adddclassepatpath> wahre </addtclassepatheps <classpathPrefix>lib/</classpathPrefix> </manifest> </archive> <classesDirectory /> </configuration> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <executions> <execution> <id>default-compile</id> <phase>compile</phase> <goals> <goal>compile</goal> </goals> </execution> <execution> <id>default-testCompile</id> <phase>test-compile</phase> <goals> <goal>testCompile</goal> </goals> </execution> </execution> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.12.4</version> <executions> <execution> <execution> <id>default-test</id> <phase>test</phase> <goals> <goal>test</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.4</version> <executions> <execution> <id>default-install</id> <phase>install</phase> <goals> <goal>install</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.7</version> <executions> <execution> <id>default-deploy</id> <phase>deploy</phase> <ziele> <giel> Einsatz </gara> </gielen> </exekutiv> </executions> </plugin> <plugin> <artifactId> maven-sieiten-plugin </artifactId> <version> 3.3 </Version> <Executions> <id> Default-Site </id> <Phase> <giele> <giele> <giele> <giele> <giele> <giele> <giele> <giele> <giele> <giele> <giele> <giele> <giele> <giele <giels> <giele <gares> <giels <outputDirectory>D:/Users/a/Workspaces/MyEclipse 2015/hellocetc/target/site</outputDirectory> <reportPlugins> <reportPlugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> </reportPlugin> </reportPlugins> </reportPlugins> </configuration> </execution> <execution> <id>default-deploy</id> <phase>site-deploy</phase> <goals> <goal>deploy</goal> </goals> <configuration> <outputDirectory>D:/Users/a/Workspaces/MyEclipse 2015/hellocetc/target/site</outputDirectory> <REPRESSPLUGINS> <REPRESSPLUGIN> <GROPRELID> org.apache.maven.plugins </GroupId> <artifactId> maven-project-info-reports-plugin </artifactId> </reportPlugin> </reportPlugins> </reportPlugins> </configuration> </executions> </executions> </executions> </executions> </execution <outputDirectory>D:/Users/a/Workspaces/MyEclipse 2015/hellocetc/target/site</outputDirectory> <reportPlugins> <reportPlugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> </reportPlugin> </reportPlugins> </configuration> </plugin> </plugins> </build> <Reporting> <outputDirectory> d:/user/a/wortsspaces/myeclipse 2015/hellocetc/target/site </outputDirectory> </reporting> </project> [info] ----------------------------------------------------------------------------------------------------------------------------------------------------------------- 2015-11-18T20: 05: 12+08: 00 [info] Endspeicher: 10m/245m [Info] ---------------------------------------------------------------------------------------------------------------------------------------------------------
Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, es wird für das Lernen aller hilfreich sein und ich hoffe, jeder wird Wulin.com mehr unterstützen.