Artikel ini memperkenalkan metode penggunaan Maven untuk menghasilkan paket toples yang dapat dieksekusi. Itu dibagikan dengan Anda. Dengan rincian sebagai berikut:
Dari XSI POM, Anda dapat membuka skema yang menggambarkan POM:
Anda dapat melihat struktur proyek di pom:
Jar yang dihasilkan oleh instalasi MVN default tidak memiliki entri kelas utama, dan kelas utama perlu diatur dalam compile-compile-plugin.
<Project xmlns = "http://maven.apache.org/pom/4.0.0" xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance" xsi: schemalocation = "http:/maven.romp.romp.romp. http://maven.apache.org/xsd/maven-4.0.0.xsd "> <podelversion> 4.0.0 </podelversion> <groupid> com.cetc.di </sroupid> <t Artifactid> HelloCetc </ArtifactId> <version> 0.0.1-SNAPSHAGING </ArtifacpIping> <version> 0.0.1.10.1.0.1 <name> HelloCetc </name> <rurl> http://maven.apache.org </ruRl> <pro properties> <poject.build.sourceencoding> UTF-8 </project.build.sourceencoding> </Properties> <dependencies> <pendeproject.build. <version> 3.8.1 </version> <scope> test </seupope> </dependency> </dependencies> <build> <dluginManagement> <dlugin> <dlugin> <groupid> org.apache.maven.plugins </groupid> <t Artifactid> Maven-Jar-plugin </Artifactid> <artifactid> Maven-jar-ptugin </Artifactid> <artifactid> Maven-Jar-plugin </Artifactid> <CRIVE> <Iprifest> <AntionClass> com.cetc.di.hellocetc.app </mainclass> <dldclasspath> true </drasclasspath> <llasspathpathphrefix> lib/</classpathpathrefix> </manifest> <archive> <classdirectory> </classpathphix> </manifest> </archive> <classdirectory> </classpathphix> </manifest> </archive> <classdirectory> </classpathrefix> </manifest> </arsip </pluginmanagement> </build> </poject>
Jalankan Instal MVN:
Di direktori target, ditemukan bahwa paket JAR telah dihasilkan:
Menggunakan Java Decompiler, Anda dapat melihat bahwa MainClass telah ditambahkan ke manifes:
Gunakan Bantuan MVN: Efektif-POM untuk melihat struktur lengkap pom.xml (termasuk properti yang diwariskan):
[Info] Pemindaian untuk proyek ... [info] [info] --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diterapkan: <!- ================================================================== ================================================================== ================================================================== ================================================================== ================================================================== ================================================================== ================================================================== =================================================================== ================================================================== =================================================================== =================================================================== =================================================================== =================================================================== =================================================================== =================================================================== =================================================================== ==========================================================KAN xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance" xsi: schemalocation = "http://maven.apache.org/pom/4.0.0 http://maven.apache.org.org/xd/. ".0 <nodelversion> 4.0.0 </ModelVersion> <GroupId> com.cetc.di </groupid> <ArTifactId> HelloCetc </artifactid> <version> 0.0.1-snapshot </version> <name> HelloCetc </name> <rurl> http://maven.apache.org </name </name> <ubl> http://maven.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> <denabled> false </denabled> </snapshots> <dent> central </drep> <name> repositori pusat </name> <rerl> https://repo.maven.apache. <Reeleases> <boatePlePolicy> tidak pernah </updatePolicy> </ereases> <snapshots> <denabled> false </denabled> </snapshots> <dent> central </depo> <name> central repository </name> <rurl> https://repo.maven.apache.orgen2 </pluginrepository> <build> <sourcedirectory> d:/user/a/workspaces/myeclipse 2015/hellocetc/src/main/java </sourcedirectory> <scriptSourcedirectory> D:/a/workspaces/myeclipse 2015/hellocoTc/scripycorcy/scripy/scripys/scripys/scripyse 2015/helloccory> <TestSourCeCtory> D:/pengguna/a/workspaces/myeclipse 2015/helloCetc/src/test/java </testsourcedirectory> <OutputDirectory> d:/user/a/workspaces/myeclipse 2015/helloCetc/target/kelas </outputdirectory> <TestOutputDirectory> D:/pengguna/a/workspaces/myeclipse 2015/helloCetc/target/kelas tes </testOutputDirectory> <urser sumber daya> <serource> <recrectory> D:/USER/A/SUMERRACRES/MYECLIPSE 2015/HELLOCETC/SRC/MAIN/SUMSROURES </Sumber Daya/Sumber Daya/Sumber Daya/Sumber Daya/Sumber Daya/Sumber Daya/Sumber Daya/Sumber Daya/Sumber Daya/Sumber Daya/Sumber Daya/Sumber Daya/Sumber Daya/Sumber Daya/Sumber Daya/Sumber Daya/Sumber Daya/Sumber/Sumber Daya/Sumber/Sumber Daya/Sumber/ <Rectory> d:/user/a/workspaces/myeclipse 2015/helloCetc/src/test/sumber daya </directory> </testResources> </testResources> <recrorcors> d:/users/a/workspaces/myeclipse 2015/helloCetc/target </directory> </a/workspaces/myeclipse 2015/helloCetc/target </directory> </directors> hell finals.0 <PluginManagement> <Plugins> <ArTifactId> maven-antrun-plugin </t Artifactid> <version> 1.3 </version> </tugin> <plugin> <RaintifactId> Maven-assembly-plugin </arttifactid> <versi> 2.2-beta-5 </versi/</versi> </artifactid> <ArtifactId> Maven-Dependency-plugin </artifactid> <version> 2.8 </version> </lugin> <lugin> <Artifactid> Maven-release- plugin </stifactid> <Artif> versi </versi </versies> </plugin> <t plugin> <Artifactid> Maven-jar </version- </plugin </plugin> <ArTifacTid> Maven-jar </version- Maven-Jar> <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> <ECECUTION> <ID> DEFAULT-RESOURCE </DD> <Thase> Proses-sumber </phase> <ject> <ject> Sumber Daya </ject> </execution> </plugin> <clugin> <ArtiFacTId> </IDECURED </ARTIFACTID> <TERECAUD> <TERECAUD> </IDED </IDED> </IDED </IDSJAUD> <TERECAUD> <TERECAUD> </IDED> </IDED> </IDED> </IDSJAUD> <TERECAUD> <TERECAUD> <TERECAUD> <TERECAUD> </IDSJAULT-2.4 </IDED> </IDSJAULT- </art <phase> Paket </phase> <ject> <eals> Jar </ject> </ject> <configuration> <source> 1.8 </source> <Target> 1.8 </target> <archive> <nan manifest> <Arainclass> com.cetc.di.hellocetc.app </MainClass> <ADDDASPATH> Tambahan </addpathespath </addpatpath </cladpath </cladpath> <cladpath> claskath </addpatpath> fl claspath </cladpath> fl claspath> addixpath </addpath> libelpath> add -claskath </claskath> </manifest> </archive> <classdirectory/> </configuration> </execution> </executions> <configuration> <source> 1.8 </source> <target> 1.8 </target> <charsive> <ifan manifest> <AdemClass> com.cetc.di.hellocetc.app </MainClass> <drenclass> <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> <ject> kompilasi </ject> </ject> </secution> <ececution> <default-TestCompile </dent> <phase> Test-Compile </phase> <ject> <eals> TestCompile </ject> </ject> </execution> </EXECUREG> </Plugin> <tugin> <ArtiFacTid> MaveneFir <version> 2.12.4 </version> <sekutif> <Ececution> <Ececution> <den> default-test </dent> <phase> tes </phase> <jetik> <jetik> tes </ject> </ject> </secuction> </execution> </ARTIFID> <ArTifactid> MAVEN-INSTALL-PLUPIN </Version> <ArTifacTID> MAVEN-INSTALL-PLOUPIN </ARTIFIUS> <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> <goals> <goal>deploy</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-site-plugin</artifactId> <version>3.3</version> <executions> <execution> <id>default-site</id> <phase>site</phase> <goals> <goal>site</goal> </goals> <configuration> <OutputDirectory> D:/USERS/A/WORKSPACES/MYECLIPSE 2015/HELLOCETC/TARGET/SITUS </OutputDirectory> <ReportPlugins> <ReportPlugin> <Groupid> org.apache.maven.plugins </groupid> <ArtiFacTid> Maven-projects </ReportPlugins> </ReportPlugins> </Configuration> </Execution> <Ececution> <dent> Default-Deploy </den> <phase> Situs-Deploy </shase> <ject> <jetik> Menyebarkan </ject/</jectpse> <configurse> <outputDirectory> D:/USER/A/PERJALANAN/PERTANDINGAN MYECRUBASI> <OutputDirectory> <ReportPlugins> <ReportPlugin> <GroupId> org.apache.maven.plugins </groupid> <ArTifactId> maven-project-info-reports-plugin </artifactid> </reportplugin> </eportplugins> </reportplugins> </konfigurasi> </reportplugin> </eportplugins> </ReportPlugins> </konfigurasi> </Execution> </ReportPlugins> </ReportPlugins> </konfigurasi> </Execution> </ReportPlugins> </ReportPlugins> </configururation> </execution <OutputDirectory> D:/USERS/A/WORKSPACES/MYECLIPSE 2015/HELLOCETC/TARGET/SITUS </OutputDirectory> <ReportPlugins> <ReportPlugin> <Groupid> org.apache.maven.plugins </groupid> <ArtiFacTid> Maven-projects </ReportPlugins> </configuration> </lugin> </lugin> </build> <poteptepting> <OutputDirectory> D:/Users/a/workspaces/myeclipse 2015/helloCetc/target/situs </outputDirectory> </pelaporan> </proyek> [info] ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 2015-11-18T20: 05: 12+08: 00 [info] Memori akhir: 10m/245m [info] ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Di atas adalah semua konten artikel ini. Saya berharap ini akan membantu untuk pembelajaran semua orang dan saya harap semua orang akan lebih mendukung wulin.com.