注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

星期五

明天不上班

 
 
 

日志

 
 
关于我

一个特立独行的Java程序员,比较宅,上上网,写博客,听音乐,看电影。

网易考拉推荐

Maven 之 assembly 插件  

2011-07-21 20:54:51|  分类: Java |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

先用mvn archetype:create 创建一个webshop项目

mvn archetype:create -DgroupId=com.hjzheng.webshop -DartifactId=webshop -Dpackagename=com.hjzheng.webshop -DarchetypeArtifactId=maven-archetype-webapp

产生的项目结构:一些文件和目录是自己加入的 (为了测试方便)

webshop/

├── pom.xml

└── src

    └── main

        ├── assembly

        ├── conf

        ├── java

        │   └── com

        │       └── hjzheng

        │           └── webshop

        │               ├── App.java

        │               └── package.properties

        └── webapp

            ├── index.jsp

            ├── WEB-INF

            │   └── web.xml

            └── webshop

                ├── app.html

                ├── css

                │   └── app.css

                └── js

                    └── app.js


我们需要的目录结构

webshop/

    ├── conf

    ├── index.jsp

    ├── lib

    │   ├── commons-beanutils-1.7.0.jar

    │   ├── commons-collections-3.2.jar

    │   └── commons-logging-1.0.3.jar

    ├── WEB-INF

    │   └── classes

    │       └── com

    │           └── hjzheng

    │               └── webshop

    │                   ├── App.class

    │                   └── package.properties

    └── webshop

        ├── app.html

        ├── css

        │   └── app.css

        └── js

            └── app.js

 

pom.xml 内容

<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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.hjzheng.webshop</groupId>

  <artifactId>webshop</artifactId>

  <packaging>war</packaging>

  <version>1.0-SNAPSHOT</version>

  <name>webshop Maven Webapp</name>

  <url>http://maven.apache.org</url>

  <build>

   <finalName>webshop</finalName>

    <outputDirectory>target/webshop-distribution/WEB-INF/classes</outputDirectory>

   <resources>

      <resource>

        <directory>src/main/java</directory> <!--处理国际化资源文件-->

        <excludes>

          <exclude>**/*.java</exclude>

        </excludes>

      </resource>

    </resources>

    <pluginManagement>

      <plugins>

        <plugin>

          <groupId>org.apache.maven.plugins</groupId>

          <artifactId>maven-compiler-plugin</artifactId>

          <configuration>

            <source>1.5</source>

            <target>1.5</target>

          </configuration>

        </plugin>

       <plugin>

          <artifactId>maven-assembly-plugin</artifactId>  <!--使用maven-assembly-plugin-->

          <version>2.2.1</version>

          <configuration>

            <descriptors>

              <descriptor>src/main/assembly/distribution.xml</descriptor>

            </descriptors>

          </configuration>

        </plugin>

      </plugins>

    </pluginManagement>

  </build>

 <dependencies>
     <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2</version>
     </dependency>
     <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.7.0</version>
     </dependency>
  </dependencies>
</project>

distribution.xml
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
  <id>distribution</id>
  <includeBaseDirectory>false</includeBaseDirectory>
  <formats>
    <format>dir</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>src/main/conf</directory>  <!--处理conf-->
      <outputDirectory>/conf</outputDirectory>
    </fileSet>
    <fileSet>
      <directory>src/main/webapp</directory>
      <outputDirectory>/</outputDirectory>
      <excludes>
        <exclude>WEB-INF/**</exclude>
      </excludes>
    </fileSet>
  </fileSets>
  <dependencySets>
    <dependencySet>
      <outputDirectory>lib</outputDirectory> <!--处理依赖的jar,放到lib目录-->
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
</assembly>

在pom.xml的目录下执行 mvn clean assembly:single compile 命令

hjzheng@ubuntu:~/app/apache-maven-3.0.3/webshop$ mvn clean assembly:single compile

[INFO] Scanning for projects...

[INFO]                                                                         

[INFO] ------------------------------------------------------------------------

[INFO] Building webshop Maven Webapp 1.0-SNAPSHOT

[INFO] ------------------------------------------------------------------------

[INFO] 

[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ webshop ---

[INFO] Deleting /home/hjzheng/app/apache-maven-3.0.3/webshop/target

[INFO] 

[INFO] --- maven-assembly-plugin:2.2.1:single (default-cli) @ webshop ---

[INFO] Reading assembly descriptor: src/main/assembly/distribution.xml

[WARNING] Cannot include project artifact: com.hjzheng.webshop:webshop:war:1.0-SNAPSHOT; it doesn't have an associated file or directory.

[INFO] Copying files to /home/hjzheng/app/apache-maven-3.0.3/webshop/target/webshop-distribution

[WARNING] Assembly file: /home/hjzheng/app/apache-maven-3.0.3/webshop/target/webshop-distribution is not a regular file (it may be a directory). It cannot be attached to the project build for installation or deployment.

[INFO] 

[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ webshop ---

[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!

[INFO] Copying 1 resource

[INFO] 

[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ webshop ---

[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!

[INFO] Compiling 1 source file to /home/hjzheng/app/apache-maven-3.0.3/webshop/target/webshop-distribution/WEB-INF/classes

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 2.643s

[INFO] Finished at: Thu Jul 21 20:51:58 CST 2011

[INFO] Final Memory: 11M/166M

[INFO] ------------------------------------------------------------------------

hjzheng@ubuntu:~/app/apache-maven-3.0.3/webshop$ 


执行成功后:

target下  webshop-distribution就是我们所需要的结构

总之 assembly插件可以灵活的帮助我们构建项目。

参考资料:

http://maven.apache.org/plugins/maven-assembly-plugin/examples/single/filtering-some-distribution-files.html

http://maven.apache.org/plugins/maven-assembly-plugin/index.html

http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

  评论这张
 
阅读(3209)| 评论(0)
推荐

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017