Este artigo apresenta o método de usar o Maven para gerar pacotes JAR executáveis. É compartilhado com você. Os detalhes são os seguintes:
Do XSI de Pom, você pode abrir o esquema que descreve POM:
Você pode ver a estrutura do projeto no POM:
O frasco gerado pela instalação padrão do MVN não possui a entrada principal da classe e a classe principal precisa ser definida no Maven-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.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd "> <ModelVersion> 4.0.0 </modelversion> <puperid> com.cetc.di </groupid> <TarifactId> hellocetc </artifactid> <uses> 0,0.1-snapshot> <name> hellocetc </name> <url> http://maven.apache.org </url> <sperSties> <projeto.build.sourcencoding> utf-8 </project.build.sourcencoding> </artes> <spenes> <pendency> <pUridId> junit> junit> <sipens> <pendency> junit> junit> <vroject> junit> <vroject> junit <pUrtifs> <vroject> junit.FUNTF <sUrtif> <vrojust> junit <rutif> junit> <vroject> junit <sUnftf> junit> <sipenci> <spenderf> <sinceft> junit. <Version> 3.8.1 </sipers> <cope> Test </scope> </dependency> </dependências> <fruct> <fluginManagement> <flugins> <lugin> <voundid> org.apache.maven.plugins </groupid> <stifactid> MAVEN-JAR-PLUGIN </Artifactid> <Rechive> <San manifest> <mainClass> com.cetc.di.hellocetc.app </mainClass> <ditclasspath> true </ddcllasspath> <mspathPrefix> lib/</clastPrefix> </manifest> </archive> <lestesdirectory> </clastrefix> </manifest> </archive> <lestes> <classes> </clastrefix> </pluginManagement> </fruct> </project>
Execute a instalação do MVN:
No diretório de destino, verifica -se que o pacote JAR foi gerado:
Usando o decompilador Java, você pode ver que o mantClass foi adicionado ao manifesto:
Use MVN Ajuda: Effeição-POM para ver a estrutura completa do POM.xml (incluindo propriedades herdadas):
[Info] Digitalização para projetos ... [Info] [Info] --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Aplicado: <!- ================================================================= ================================================================= ================================================================= ================================================================= ================================================================= ================================================================= ================================================================= ================================================================== ================================================================= ================================================================== ================================================================== ================================================================== ================================================================== ================================================================== ================================================================== ================================================================== =========================================================================== -> <Project XMLNS = "Http./mav. 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-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.cetc.di</groupId> <artifactId>hellocetc</artifactId> <version>0.0.1-SNAPSHOT</version> <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> <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> <Tapetarpolicy> nunca </putapolicy> </leaseases> <snapshots> <bedable> false </itilabed> </snapshots> <id> central </dod> <name> repositório central </name> <url> https://repo.maven.apache.org/maven2 </url> <SourceDirectory> d:/users/a/workspaces/myeclipse 2015/hellocetc/src/main/java </oucederceDirectory> <ScriptSourceDirectory> d:/users/a/workspaces/myeclipse 2015/hellocetc/src/main/scripts </scripts </scripts </scripts/scripts/scripts/scripts/scripts/scripts/scripts/myeclipse 2015/hellocetc/src/main/scripts </scripts <TestSourceDirectory> d:/users/a/workspaces/myeclipse 2015/hellocetc/src/test/java </testsourcedirectory> <putedDirectory> d:/users/a/workspaces/myeclipse 2015/hellocetc/alvo/classes </hellocetcy <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:/users/a/workspaces/myeclipse 2015/hellocetc/src/test/recursos </diretório> </testResources> </sestresources> <cirectory> d:/users/a/workspaces/myeclipse 2015/hellocetc/alvo </Directory> <tinName> hellocet. <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> <Versão> 2.8 </version> </plugin> <lampleg> <ArtifactId> Maven-Release-Plugin </stiltifactid> <versão <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> <lugins> <TRATIFACTID> maven-clean-plugin </stutifactId> <versão> 2.5 </sipers> </execuções> <Excution> <dent> padrão <d-cl-clean </ds> <shase> </secution> </meta </metal> limpeza </metal> </tent> <dent> <dent> clean-clean </ds> <shase> </testecion> </meta </metal> limpeza </metal> </tent> <dent> <dent> <dent> clean-clean </ds> <shase> </socion> </tecent> </meta> limpe <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> <di> Pacote padrão-jar </dod> <shase> </shase> <gestes> <Goal> jar </as Goal> </metas> <figuration> <socorM> 1.8 </sourder> <lection> 1.8 </-TARGEN> <CHIVE> </manifest> <-mantclass> com.cetc.di.hellocetc.apppath </mantclass> <-mantclass> com.cetc.di.hellocetc.apppypath </mantclass> <classpathPrefix>lib/</classpathPrefix> </manifest> </archive> <classesDirectory /> </configuration> </execution> </executions> <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> <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> <TRAFACTID> MAVEN-INSTALL-PLUGIN </ARTIFACTID> <Versão> 2.4 </Version> <Comestions> <Execution> <id> padrão-instalação </dod> <shase> Install </shase> </meta </Plugin> Install </Goal> </metas </stecution> </execuções> </Plugin> <glug> </Plugin <TarifactId> maven-desployplo-plugin </artifactId> <versão> 2.7 </version> <correcions> <Execution> <id> padrão-deploy </dod> <shase> implantar </shase> </meta </plugin> implantar </age> </forgin> </metas> </execution> </plugin> <clugin> <clugin> <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/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> <reportPlugins> <reportPlugin> <PuerpId> org.apache.maven.plugins </groupId> <TROTIFACTID> maven-project-info-reports-pplugin </artifactId> </reportplugin> </reportplugins> </reportplugins> </figuration> </execution> </executins> <lincigature> <putputDirectory> d:/users/a/workspaces/myeclipse 2015/hellocetc/target/site </itputDirectory> <ReportPlugins> <lorporPlugin> <purfactid> org.apache.maven.plugins </groupid> Artifactid> MAVEN-Project-in -prets. </reportplugins> </figuration> </plugin> </plugins> </build> <lorporation> <putputDirectory> d:/users/a/workspaces/myeclipse 2015/hellocetc/target/site </outputDirectory> </satelinging> </projection> [info] • 2015-11-18T20: 05: 12+08: 00 [Info] Memória final: 10m/245m [Info] -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
O exposto acima é todo o conteúdo deste artigo. Espero que seja útil para o aprendizado de todos e espero que todos apoiem mais o wulin.com.