Maven打成可执行的jar包_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Maven打成可执行的jar包

Maven打成可执行的jar包

 2013/8/21 18:47:41  yuan8606  程序员俱乐部  我要评论(0)
  • 摘要:在pom.xml里加这段话,和<dependencies>同级。<build><pluginManagement><plugins><plugin><groupId>org.eclipse.m2e</groupId><artifactId>lifecycle-mapping</artifactId><version>1.0.0</version><
  • 标签:执行 Maven
在pom.xml里加这段话,和<dependencies>同级。
<build>
<pluginManagement>
  <plugins>
   <plugin>
    <groupId>org.eclipse.m2e</groupId>
    <artifactId>lifecycle-mapping</artifactId>
    <version>1.0.0</version>
     <configuration>
      <lifecycleMappingMetadata>
       <pluginExecutions>
        <pluginExecution>
         <pluginExecutionFilter>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
          <versionRange>[2.0,)</versionRange>
          <goals>
           <goal>copy-dependencies</goal>
           <goal>unpack</goal>
          </goals>
         </pluginExecutionFilter>
         <action>
         <ignore />
         </action>
        </pluginExecution>
       </pluginExecutions>
      </lifecycleMappingMetadata>
     </configuration>
    </plugin>
   </plugins>
  </pluginManagement>
   <plugins>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
     <version>2.3.2</version>
     <configuration>
      <source>1.7</source>
      <target>1.7</target>
      <encoding>UTF-8</encoding>
     </configuration>
    </plugin>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-jar-plugin</artifactId>
     <configuration>
      <archive>
       <manifest>
        <addClasspath>true</addClasspath>
        <classpathPrefix>lib/</classpathPrefix>
        <mainClass>com.Main</mainClass>
       </manifest>
      </archive>
     </configuration>
    </plugin>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-dependency-plugin</artifactId>
     <executions>
      <execution>
       <id>copy</id>
       <phase>install</phase>
       <goals>
        <goal>copy-dependencies</goal>
       </goals>
       <configuration> 
        <outputDirectory>${project.build.directory}/lib</outputDirectory>
       </configuration>
      </execution>
     </executions>
    </plugin>
   </plugins>
</build>
执行mvn clean install
jar内如有配置文件,最好用流的方式读取,否则很可能读取错误
最后编写一个*.bat文件,内容如下:
@echo off
@title
java   -jar **.jar
pause
发表评论
用户名: 匿名