この記事では、Mavenを使用して実行可能なJARパッケージを生成する方法を紹介します。それはあなたと共有されます。詳細は次のとおりです。
POMのXSIから、POMを説明するスキーマを開くことができます。
POMでプロジェクトの構造を見ることができます。
デフォルトのMVNインストールによって生成されたJARにはメインクラスのエントリがなく、メインクラスは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.apach/4.0. http://maven.apache.org/xsd/maven-4.0.0.xsd "> <modelversion> 4.0.0 </modelversion> <groupid> com.cetc.di </groupid> <artifactid> hellocetc </artifactid> <バージョン<name> hellocetc </name> <url> http://maven.apache.org </url> <properties> <project.build.sourceencoding> utf-8 </project.build.sourceencoding> </properties> <seplencies> <shionid </groupid </groupid> <バージョン> 3.8.1 </version> <scope> test </scope> </dependency> </dependencies> <burtion> <bluginmanagement> <plugins> <plugin> <groupid> org.apache.maven.plugins </groupid> <artifactid> maven-jar-plugin </artifactid> <fortation> <Archive> <manifest> <mainclass> com.cetc.di.hellocetc.app </mainclass> <addclasspath> true </addclasspath> <classpathprefix> lib/</classpathprefix> </manifest> </archive> <classesdirectory> </pluginmanagement> </build> </project>
MVNインストールを実行します:
ターゲットディレクトリでは、JARパッケージが生成されていることがわかります。
Java Decompilerを使用して、Mainclassがマニフェストに追加されていることがわかります。
MVNヘルプを使用してください:Effective-POMは、pom.xmlの完全な構造を確認します(継承されたプロパティを含む):
[情報]プロジェクトのスキャン... [情報] [情報] ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------適用:<! - ================================================================================ ================================================================================ ================================================================================ ================================================================================ ================================================================================ ================================================================================ ================================================================================ ============================================================================== ================================================================================ ============================================================================== ============================================================================== ============================================================================== ============================================================================== ============================================================================== ============================================================================== ============================================================================== ======================================================================================= 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.0.0.0.0.0.0. <modelversion> 4.0.0 </modelversion> <groupid> com.cetc.di </groupid> <artifactid> hellocetc </artifactid> <バージョン> 0.0.1-snapshot </version> <name> hellocetc </name> <url> http://maven.apach.org.org </url <propties> <project.build.sourceencoding> utf-8 </project.build.sourceencoding> </properties> <dependencies> <dependency> <groupid> junit </groupid> <artifactid> junit </artifactid> <バージョン> 3.8.1 </バージョン>テスト</desposies> </scope> <SnapShots> <Enabled> false </enabled> </snapshots> <id> central </id> <name> central Repository </name> <url> https://repo.maven.apache.org/maven2 </url> </repository> </repository> </repository> </reposion <LELEASES> <updatePolicy> never </updatePolicy> </lileases> <snapshots> <enabled> false </enabled> </snapshots> <id> central </id> <name> centralリポジトリ</name> <url> https://repo.maven.apache.org/maven2 </url> </plug </plaginRepository> <build> <Sourcedirectory> D:/users/a/a/workspaces/myeclipse 2015/hellocetc/src/main/java </sourcedirectory> <scordsourcedirectory> d:/users/a/workspaces/myeclipse 2015/hellocetc/src/scripts <TestSourcedirectory> D:/users/a/workspaces/myeclipse 2015/hellocetc/src/java </testsourcedirectory> <outputdirectory> d:/workspaces/myeclipse 2015/hellocetc/ターゲット/クラス</outpotdectory> <TestOutputDirectory> D:/users/a/workspaces/myeclipse 2015/hellocetc/ターゲット/テストクラス</testoutputdirectory> <resources> <resource> <directory> d:/workspaces/myeclipse 2015/hellocetc/src/main/resource> </resource> </<testress> <Directory> d:/users/a/workspaces/myeclipse 2015/hellocetc/src/test/resources </directory> </testresources> </testresources> <directory> d:/users/a/workspaces/myeclipse 2015/hellocetc/target </directory> <finalname> hellocetc-0.0.1 <PluginManagement> <Plugins> <artifactid> maven-anntrun-plugin </artifactid> <version> 1.3 </version> </plugin> <plugin> <artifactid> maven-assembly-plugin </artifactid> <バージョン> 2.2-ベータ-5/バージョン> <artifactid> maven-dependency-plugin </artifactid> <version> 2.8 </version> </plugin> <plugin> <artifactid> </artifactid> <バージョン> 2.3.2 </version> </plugin> <plugin> <artifacin <configuration> <source> 1.8 </source> <target> 1.8 </target> <archive> <manifest> <mainclass> com.cetc.di.hellocetc.app </mainclass> <addclasspath> true </addclasspath> <classpathprefix> lib/</classpath> </manifest> </manifest> </manifest> </plugin> </plugins> </plugins> </pluginmanagement> <plugins> <artifactid> maven-clean-plugin </artifactid> <バージョン> 2.5 </version> <実行> <実行> <id> default-clean </id> <phas> cleas> cleas> <ゴール> <Artifactid> maven-resources-plugin </artifactid> <version> 2.6 </version> <executions> <execution> <id> default-testResources </id> <phase>プロセステスト - リソース</フェーズ> <ゴール> <ゴール> testResources </goal> </goal> </execution> <execution> </execution> </execution> </execution <Execution> <id> default-resources </id> <phase> process-resources </phase> <goal>リソース</goal>リソース</goal> </execution> </plugin> <plugin> <artifactid> maven-jar-plugin </artifactid> <バージョン> 2.4 </バージョン> <実行<goal> jar </goal> </goal> <Configuration> <source> 1.8 </source> <target> 1.8 </target> <Archive> <manifest> <mainclass> com.cetc.di.hellocetc.app </mainclass> <addclasspath> <classesdirectory/> </configuration> </execution> </executions> <configuration> <source> 1.8 </source> <target> 1.8 </target> <arcive> <manifest> <mainclass> com.cetc.di.hellocetc.app </mainclass> <addclaspath </manifest> </archive> <classesdirectory/> </configuration> </plugin> <plugin> <artifactid> maven-compiler-plugin </artifactid> <バージョン> 3.1 </バージョン> <実行> <実行> <id> default-id> default-compile </id> </</exec> <Execution> <id> default-testCompile </id> <phase> test-compile </phase> <goal> testCompile </goal> </goal> </execution> </execution> </plugin> <artifactid> maven-surefire-plugin </artifactid> <id>デフォルトテスト</id> <phase> test </phase> <gogle> test </goal> </goal> </goal> </execution> </executions> </plugin> <plugin> <artifactid> maven-install-plugin </artifactid> <バージョン> 2.4 </バージョン> <実行> <goal> install </goal> </goal> </execution> </executions> </plugin> <plugin> <artifactid> maven-deploy-plugin </artifactid> <バージョン> 2.7 </バージョン> <実行> <execution> <id> default-deploy </id> </expoly> deaplopinoply> </executions> </plugin> <plagin> <artifactid> maven-site-plugin </artifactid> <version> 3.3 </version> <executions> <execution> <id> <id> default-site </id> <phase> site> 2015/hellocetc/target/site </outputDirectory> <ReportPlugins> <ReportPlugin> org.apache.maven.plugins </groupid> <artifactid> maven-project-info-reports-plugin </artifactid> </reportplugin> </reputurations> <Execution> <id> default-deploy </id> <phase> site-deploy </phase> <goal> deploy> deploy </goal> </goal> </goal> <configuration> <outputdirectory> d:/users/a/workspaces/myeclipse 2015/hellocetc/ターゲット/ターゲット/サイト</outputdirectory> <Reportplugins> <groupid> org.apache.maven.plugins </groupid> <artifactid> maven-project-info-reports-plugin </artifactid> </reportplugin> </reportplugins> </reportplugins> </configuration> </execution> </my execuration 2015/hellocetc/target/site </outputDirectory> <ReportPlugins> <ReportPlugin> <groupId> org.apache.maven.plugins </groupid> <artifactid> maven-project-info-reports-plugin </artifactid> </repumplugin> </bult> </>>> < <Reporting> <OutputDirectory> d:/users/a/workspaces/myeclipse 2015/hellocetc/target/site </outputdirectory> </reporting> </project> [info] ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 2015-11-18T20:05:12+08:00[INFO] Final Memory: 10M/245M[INFO] ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。