`
qqj_1979
  • 浏览: 4428 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

java学习笔记系列(1)---maven打包

    博客分类:
  • JAVA
 
阅读更多

 

当前java工程通用工具:
1、开发工具IDE:Eclipse
2、项目管理工具:Maven
 
代码开发完毕,如何打成jar包?如何打成整个运行的包?
 
1、如何打成jar包?
1))创建maven工程后,执行 maven install即可自动生成jar包;
2)pom.xml中增加如下配置,可以打包源码包;
     <build>
          <plugins>
               <plugin>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>2.1</version>
                    <executions>
                         <execution>
                              <phase>compile</phase>
                              <goals>
                                   <goal>jar</goal>
                              </goals>
                         </execution>
                    </executions>
               </plugin>
          </plugins>
     </build>
 
 
2、如何打成运行包?
1)pom.xml中增加如下配置,可以打包运行包;
<build >
            <resources >
                 <resource >
                      <directory >src/main/resources</ directory>
                      <targetPath >${project.build.directory}/ conf</ targetPath>
                 </resource >
            </resources >
            <plugins >
                 <plugin >
                      <artifactId >maven-jar-plugin</artifactId >
                      <configuration >
                            <archive >
                                 <manifest >
                                      <addClasspath >true </addClasspath >
                                      <classpathPrefix >lib </classpathPrefix >
                                      <mainClass >${maven.main.class} </mainClass >
                                 </manifest >
                                 <manifestEntries >
                                      <Class-Path >conf/ </Class-Path >
                                 </manifestEntries >
                            </archive >
                            <excludes >
                                 <exclude >src/main/resources/** </exclude >
                            </excludes >
                      </configuration >
                 </plugin >
                 <plugin >
                      <artifactId >maven-assembly-plugin</artifactId >
                      <version >2.4 </version >
                      <executions >
                            <execution >
                                 <id >make-tar.gz </id >
                                 <phase >package </phase >
                                 <goals >
                                      <goal >single </goal >
                                 </goals >
                                 <configuration >
                                      <finalName >${maven.gz.name} </finalName >
                                      <skipAssembly >false </skipAssembly >
                                      <descriptors >
                                           <descriptor >tar.gz.xml </descriptor >
                                      </descriptors >
                                 </configuration >
                            </execution >
                      </executions >
                 </plugin >
            </plugins >
     </build >
      
2)tar.gz.xml文件:
<?xml version="1.0" encoding= "UTF-8"?>


<assembly 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/assembly-1.0.0.xsd" >
     <id >package </id >
     <formats >
            <format >tar.gz </format >
     </formats >
     <includeBaseDirectory >false </includeBaseDirectory >
     <fileSets >
            <fileSet >
                 <directory >bin </directory >
                 <outputDirectory >/ </outputDirectory >
                 <fileMode >0755 </fileMode >  //说明:设置bin目录下文件的操作权限 -rwxr-xr-x  1 root    root         340 Jan  9 10:22 video-itenv.sh
                 <directoryMode >0755 </directoryMode >
            </fileSet >
            <fileSet >
                 <directory >${project.build.directory}/ conf</ directory>
                 <outputDirectory >/ conf</ outputDirectory>
            </fileSet >
     </fileSets >
     <files >
            <file >
                 <source >${project.build.directory}/${project.build.finalName}.jar </source >
                 <destName >/${project.build.finalName}.jar </destName >
            </file >
     </files >
     <dependencySets >
            <dependencySet >
                 <outputDirectory >lib</outputDirectory>
                 <scope >runtime </scope >
            </dependencySet >
     </dependencySets >
</assembly>
 
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics