91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

使用maven怎么生成一個可執行的jar包

發布時間:2021-03-26 17:29:49 來源:億速云 閱讀:172 作者:Leah 欄目:編程語言

今天就跟大家聊聊有關使用maven怎么生成一個可執行的jar包,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。

從pom的xsi中可以打開描述pom的schema:

使用maven怎么生成一個可執行的jar包

可以看到pom中,project的結構:

使用maven怎么生成一個可執行的jar包

默認的mvn install生成的jar是不帶主類入口的,需要在maven-compile-plugin中設置主類,

使用maven怎么生成一個可執行的jar包

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

 <groupId>com.cetc.di</groupId>
 <artifactId>hellocetc</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>jar</packaging>

 <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>
    <archive>
      <manifest>
        <mainClass>com.cetc.di.hellocetc.App</mainClass>
        <addClasspath>true</addClasspath>
      <classpathPrefix>lib/</classpathPrefix>
      </manifest>

    </archive>
    <classesDirectory>
    </classesDirectory>
  </configuration>
</plugin>
</plugins>  
</pluginManagement>
</build> 
</project>

執行mvn install:

使用maven怎么生成一個可執行的jar包

在target目錄中,發現jar包已經生成:

使用maven怎么生成一個可執行的jar包

用java decompiler,可以看到manifest中已經加入了MainClass:

使用maven怎么生成一個可執行的jar包

使用mvn help:effective-pom可以看到pom.xml的完整結構(包括繼承而來的屬性):

使用maven怎么生成一個可執行的jar包

[INFO] Scanning for projects...
[INFO]                                     
[INFO] ------------------------------------------------------------------------
[INFO] Building hellocetc 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-help-plugin:2.2:effective-pom (default-cli) @ hellocetc ---
[INFO] 
Effective POMs, after inheritance, interpolation, and profiles are applied:

<!-- ====================================================================== -->
<!--                                    -->
<!-- Generated by Maven Help Plugin on 2015-11-18T08:05:12         -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/        -->
<!--                                    -->
<!-- ====================================================================== -->

<!-- ====================================================================== -->
<!--                                    -->
<!-- Effective POM for project 'com.cetc.di:hellocetc:jar:0.0.1-SNAPSHOT'  -->
<!--                                    -->
<!-- ====================================================================== -->

<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>
 <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>
 </repositories>
 <pluginRepositories>
  <pluginRepository>
   <releases>
    <updatePolicy>never</updatePolicy>
   </releases>
   <snapshots>
    <enabled>false</enabled>
   </snapshots>
   <id>central</id>
   <name>Central Repository</name>
   <url>https://repo.maven.apache.org/maven2</url>
  </pluginRepository>
 </pluginRepositories>
 <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:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\test\java</testSourceDirectory>
  <outputDirectory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\classes</outputDirectory>
  <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>
   </resource>
  </resources>
  <testResources>
   <testResource>
    <directory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\test\resources</directory>
   </testResource>
  </testResources>
  <directory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target</directory>
  <finalName>hellocetc-0.0.1-SNAPSHOT</finalName>
  <pluginManagement>
   <plugins>
    <plugin>
     <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>
  </pluginManagement>
  <plugins>
   <plugin>
    <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>
      <phase>process-resources</phase>
      <goals>
       <goal>resources</goal>
      </goals>
     </execution>
    </executions>
   </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>
       </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>
    </executions>
   </plugin>
   <plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12.4</version>
    <executions>
     <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>
      <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\site</outputDirectory>
       <reportPlugins>
        <reportPlugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-project-info-reports-plugin</artifactId>
        </reportPlugin>
       </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>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-project-info-reports-plugin</artifactId>
        </reportPlugin>
       </reportPlugins>
      </configuration>
     </execution>
    </executions>
    <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>
    </configuration>
   </plugin>
  </plugins>
 </build>
 <reporting>
  <outputDirectory>D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\site</outputDirectory>
 </reporting>
</project>

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.526 s
[INFO] Finished at: 2021-03-18T20:05:12+08:00
[INFO] Final Memory: 10M/245M
[INFO] ------------------------------------------------------------------------

看完上述內容,你們對使用maven怎么生成一個可執行的jar包有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

格尔木市| 松溪县| 桂林市| 泽州县| 贵南县| 叶城县| 清水县| 平南县| 乐清市| 四平市| 马边| 双牌县| 克东县| 剑川县| 老河口市| 塘沽区| 旌德县| 彭州市| 平顺县| 江陵县| 拉萨市| 新民市| 营口市| 安吉县| 嘉祥县| 那曲县| 普定县| 阿坝县| 麻栗坡县| 华亭县| 日土县| 定西市| 贵德县| 秦安县| 桂东县| 安仁县| 宜春市| 砀山县| 石景山区| 油尖旺区| 大理市|