`
san_yun
  • 浏览: 2651635 次
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

使用maven-assembly-plugin打包

 
阅读更多

有时候希望能把部署环境build在project,这样部属更加方便。

先说遇到的一个错误:

[INFO] No files selected for line-ending conversion or filtering. Skipping: /duitang/dist/app/trunk/java/mytest/src/jetty/resource
[INFO] No files selected for line-ending conversion or filtering. Skipping: /duitang/dist/app/trunk/java/mytest/conf/my
[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o  'commons-logging:commons-logging'

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.910s
[INFO] Finished at: Thu Apr 17 11:54:43 CST 2014
[INFO] Final Memory: 9M/208M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single (make-assembly) on project japa: Assembly is incorrectly configured: null: Assembly is incorrectly configured: null:
[ERROR] Assembly: null is not configured correctly: One or more filters had unmatched criteria. Check debug log for more information.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

 

我之前之注意到这句话: 

null is not configured correctly: One or more filters had unmatched criteria. Check debug log for more information.

 

但这句话啥意思也没说。其实关键的是这句:

[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o 'commons-logging:commons-logging'

使用 assembly.xml要求你必须依赖一些包。

基本上包括下面这些都是必须的:

    <dependencies>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
       
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>start</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-util</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jsp-2.1-jetty</artifactId>
            <version>${jetty.version}</version>
        </dependency>
    </dependencies>

 下面是一个完整的配置:

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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.duitang</groupId>
    <artifactId>japa</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>japa</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jetty.version>6.1.26</jetty.version>
        <maven.test.skip>true</maven.test.skip>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
        <maven.compiler.compilerVersion>1.6</maven.compiler.compilerVersion>
    </properties>
    <dependencies>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
       
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>start</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-util</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jsp-2.1-jetty</artifactId>
            <version>${jetty.version}</version>
        </dependency>
       
    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                    <include>**/*.txt</include>
                    <include>**/*.key</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <includes>
                        <include>**/*.properties</include>
                        <include>**/*.xml</include>
                        <include>**/*.txt</include>
                        <include>**/*.class</include>
                        <include>**/*.key</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <id>make-a-jar</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
	  
	   <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <archiveClasses>true</archiveClasses>
                    <webxml>src/web/web.xml</webxml>
                    <webResources>
                        <resource>
                            <directory>src/web</directory>
                            <targetPath>WEB-INF</targetPath>
                            <filtering>false</filtering>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>		

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2-beta-5</version>
                <configuration>
                    <finalName>app</finalName>
                    <attach>false</attach>
                    <descriptors>
                        <descriptor>assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

</project>

 

assembly.xml

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1 http://maven.apache.org/xsd/assembly-1.1.1.xsd"
>
    <formats>
        <format>dir</format>
        <!-- format>tar.gz</format -->
	<!-- format>dir</format -->
    </formats>
    <dependencySets>
        <dependencySet>
            <!-- unpack the webapp as root application -->
            <scope>runtime</scope>
            <unpack>true</unpack>
            <outputDirectory>webapps/${artifactId}</outputDirectory>
            <includes>
                <include>${groupId}:${artifactId}:war</include>
            </includes>
        </dependencySet>
        <dependencySet>
            <unpack>false</unpack>
            <outputDirectory>lib</outputDirectory>
            <useTransitiveFiltering>true</useTransitiveFiltering>
            <useStrictFiltering>true</useStrictFiltering>
            <fileMode>666</fileMode>
            <includes>
                <include>org.mortbay.jetty:jetty</include>
                <include>org.mortbay.jetty:jetty-util</include>
                <include>org.mortbay.jetty:start</include>
                <include>org.mortbay.jetty:jsp-2.1-jetty</include>
                <include>commons-logging:commons-logging</include>
                <include>log4j:log4j</include>
            </includes>
        </dependencySet>
    </dependencySets>
    <fileSets>
        <fileSet>
            <directory>src/jetty/etc</directory>
            <outputDirectory>etc/</outputDirectory>
            <filtered>false</filtered>
        </fileSet>
        <fileSet>
            <directory>src/jetty/logs</directory>
            <outputDirectory>logs/</outputDirectory>
            <filtered>false</filtered>
        </fileSet>
        <fileSet>
            <directory>src/jetty/resource</directory>
            <outputDirectory>resource/</outputDirectory>
            <filtered>true</filtered>
            <includes>
                <include>log4j.properties</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>${propsdir}</directory>
            <outputDirectory>webapps/${artifactId}/WEB-INF/</outputDirectory>
            <filtered>true</filtered>
            <excludes>
                <exclude>log4j.properties</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <directory>src/js</directory>
            <outputDirectory>webapps/${artifactId}/js/</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>src/jetty/bin</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>*.sh</include>
            </includes>
            <fileMode>0755</fileMode>
        </fileSet>
    </fileSets>
</assembly>

 

另外需要把jetty和web目录放在src中,见附件(如果无需安环境切分,config可以不需要)。

 

补充:下面是精简方案

<?xml version="1.0" encoding="UTF-8"?>
<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>
	<artifactId>tlog-proxy</artifactId>
	<packaging>war</packaging>
	<name>TLog Proxy Server</name>
	<properties> 
		 <jetty.version>6.1.26</jetty.version>   
	</properties>
	<dependencies>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>start</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-util</artifactId>
            <version>${jetty.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jsp-2.1-jetty</artifactId>
            <version>${jetty.version}</version>
        </dependency>	
	</dependencies>


	<build>
		<resources>
			<resource>
				<directory>src/main/java</directory>
				<includes>
					<include>**/*.properties</include>
					<include>**/*.xml</include>
					<include>**/*.txt</include>
					<include>**/*.key</include>
				</includes>
			</resource>
		</resources>
		<plugins>
			<plugin>
				<artifactId>maven-assembly-plugin</artifactId>
				<version>2.2-beta-5</version>
				<configuration>
					<finalName>tlog-proxy</finalName>
					<attach>false</attach>
					<descriptors>
						<descriptor>assembly.xml</descriptor>
					</descriptors>
				</configuration>
				<executions>
					<execution>
						<id>make-assembly</id>
						<phase>package</phase>
						<goals>
							<goal>single</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
	
</project>

 

assembly.xml

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1 http://maven.apache.org/xsd/assembly-1.1.1.xsd"
>
    <formats>
        <format>tar.gz</format>
        <!-- format>tar.gz</format -->
		<!-- format>dir</format -->
    </formats>
    <dependencySets>
        <dependencySet>
            <!-- unpack the webapp as root application -->
            <scope>runtime</scope>
            <unpack>true</unpack>
            <outputDirectory>webapps/${artifactId}</outputDirectory>
            <includes>
                <include>${groupId}:${artifactId}:war</include>
            </includes>
        </dependencySet>
        <dependencySet>
            <unpack>false</unpack>
            <outputDirectory>lib</outputDirectory>
            <useTransitiveFiltering>true</useTransitiveFiltering>
            <useStrictFiltering>true</useStrictFiltering>
            <fileMode>666</fileMode>
            <includes>
                <include>org.mortbay.jetty:jetty</include>
                <include>org.mortbay.jetty:jetty-util</include>
                <include>org.mortbay.jetty:start</include>
                <include>org.mortbay.jetty:jsp-2.1-jetty</include>
                <include>commons-logging:commons-logging</include>
                <include>log4j:log4j</include>
            </includes>
        </dependencySet>
    </dependencySets>
    <fileSets>
    	<fileSet>
            <directory>src/main/resources</directory>
            <outputDirectory>webapps/${artifactId}/WEB-INF/classes</outputDirectory>
            <includes>
                <include>*.xml</include>
                <include>*.properties</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>src/jetty/etc</directory>
            <outputDirectory>etc/</outputDirectory>
            <filtered>false</filtered>
        </fileSet>
        <fileSet>
            <directory>src/jetty/logs</directory>
            <outputDirectory>logs/</outputDirectory>
            <filtered>false</filtered>
        </fileSet>
        <fileSet>
            <directory>src/jetty/resource</directory>
            <outputDirectory>resource/</outputDirectory>
            <filtered>true</filtered>
            <includes>
                <include>log4j.properties</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>${propsdir}</directory>
            <outputDirectory>webapps/${artifactId}/WEB-INF/</outputDirectory>
            <filtered>true</filtered>
            <excludes>
                <exclude>log4j.properties</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <directory>src/js</directory>
            <outputDirectory>webapps/${artifactId}/js/</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>src/jetty/bin</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>*.sh</include>
            </includes>
            <fileMode>0755</fileMode>
        </fileSet>
    </fileSets>
</assembly>

 

分享到:
评论

相关推荐

    SpringBoot项目使用maven-assembly-plugin根据不同环境打包成tar.gz或者zip

    总的来说,`maven-assembly-plugin`是Maven构建过程中的一个重要工具,它帮助开发者灵活地定制打包过程,适应不同环境的需求。结合Spring Boot项目,我们可以更高效地管理和部署应用程序,提高开发和运维的效率。

    Maven build插件之Maven-assembly-plugin自定义打包

    Maven-assembly-plugin是maven中针对打包任务而提供的标准插件,可以实现自定义打包。主要提供如下功能: ● 提供一个把工程依赖元素、模块、网站文档等其他文件存放到单个归档文件里。 ● 打包成指定格式分发包,...

    Maven3种打包方式中maven-assembly-plugin的使用详解

    Maven3种打包方式中maven-assembly-plugin的使用详解 Maven 作为一个流行的项目管理工具,提供了多种方式来打包项目。其中,maven-assembly-plugin 是一个非常强大和灵活的插件,支持自定义的打包结构,并且可以...

    maven打包dubbo服务接口(maven-assembly-plugin)

    本篇文章将详细探讨如何使用Maven的`maven-assembly-plugin`插件来打包Dubbo服务接口。 首先,我们要理解Maven的生命周期和构建过程。Maven有多个生命周期阶段,如`clean`、`compile`、`test`、`package`等,每个...

    maven-shade-plugin-3.1.0.jar

    maven打包,指定入口类的jar包,具体的pom配置为:&lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins &lt;artifactId&gt;maven-shade-plugin &lt;version&gt;3.1.0 &lt;phase&gt;package &lt;goal&gt;shade implementation=...

    maven-assembly 自定义打包方式

    而`maven-assembly-plugin`是Maven的一个插件,用于创建自定义的打包(assembly)格式,比如tar、tar.gz、zip等。这个插件允许开发者在打包过程中包含额外的资源,如配置文件、文档等,使得最终的发布包更完整,便于...

    Maven 生成打包可执行jar包的方法步骤

    接下来,使用maven-assembly-plugin打包项目,主要配置如下: ```xml &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins &lt;artifactId&gt;maven-assembly-plugin &lt;version&gt;2.4 &lt;descriptor&gt;src/main/resources/...

    Spring Boot项目使用maven-assembly-plugin根据不同环境打包成tar.gz或者zip.zip

    maven安装与配置 确保已安装JDK。Maven 3.9+版本需要JDK 8或更高版本。可以通过输入java -version来检查JDK是否安装以及其版本。 下载Maven。访问Maven官网下载最新版本,例如3.9.1。对于Windows用户,通常下载...

    maven资料Maven Assembly Plugin

    下面是一个具体的配置示例,用于说明如何使用 Maven Assembly Plugin: ```xml &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins &lt;artifactId&gt;maven-assembly-plugin &lt;version&gt;2.6 &lt;mainClass&gt;...

    xmljava系统源码-spring-boot-assembly:SpringBoot项目使用maven-assembly-plugin根据不

    maven-assembly-plugin maven-jar-plugin spring-boot-maven-plugin maven-dependency-plugin maven-resources-plugin CHANGELOG 1.maven-assembly-plugin 配置assembly.xml文件路径 &lt;plugin&gt; &lt;artifactId&gt;maven-...

    maven打包使用yui压缩css和js文件

    在Maven中实现这个功能,我们需要借助maven-assembly-plugin或者maven-war-plugin,但更常见的是使用maven-resources-plugin和maven-compiler-plugin配合yuicompressor-maven-plugin。以下是一个详细的步骤说明: 1...

    maven plugin打包下载

    在Java开发领域,Maven是一个不可或缺的构建工具,它通过管理项目的依赖关系,简化了构建...对于`maven plugin打包下载`这个主题,理解其工作原理、生命周期和配置方式至关重要,这将直接影响到项目的构建和打包过程。

    揭秘 Maven 的打包神器:深入解析 maven-assembly-plugin 的工作机制

    1. **项目对象模型(POM)**:Maven 使用一个 XML 文件(通常是 `pom.xml`)来描述项目的基本信息、构建过程、依赖关系等。 2. **依赖管理**:Maven 能够自动处理项目所需的所有外部依赖,开发者不需要手动下载和...

    demo-maven-pkg.zip

    总结来说,这个"demo-maven-pkg.zip"是使用Maven的插件功能,可能结合`maven-assembly-plugin`或`maven-resources-plugin`,将一个Maven项目及其相关资源和依赖打包成ZIP格式的文件,便于分发和部署。具体的内容和...

    springboot+maven打包demo【将依赖与配置文件打包到jar包外部】

    1. **依赖打包到外部**:使用`maven-assembly-plugin`或`maven-shade-plugin`,我们可以将依赖打包到一个单独的lib目录下。比如,通过`maven-assembly-plugin`的`dependencySet`配置,我们可以指定哪些依赖应该被...

    apache-maven-3.3.9.zip

    例如,`maven-surefire-plugin` 用于运行单元测试,`maven-javadoc-plugin` 可生成API文档,而`maven-assembly-plugin` 或`maven-resources-plugin` 则帮助创建可分发的工件。 Apache Maven 3.3.9 版本相对于之前的...

    Maven将带有第三方依赖的可执行程序打包示例

    java 写的可执行程序怎么使用 maven 打包? 执行程序中有巨多第三方依赖包,要一起打进 jar 包,怎么办? maven-assembly-plugin 插件打第三方依赖包进 jar,spring 有 org.springframework.beans.factory.parsing....

    apache-maven-3.1.0-bin.tar

    例如,`maven-assembly-plugin`可以用来创建自定义的打包格式,`maven-javadoc-plugin`则用于生成项目文档。 至于"Readme-说明.htm"文件,通常包含有关如何安装、配置和使用Maven的详细信息。用户应仔细阅读该文件...

    Apache-Maven-3.6.3.rar

    例如,maven-surefire-plugin用于执行单元测试,maven-javadoc-plugin生成API文档,maven-assembly-plugin则能打包成可分发的格式,如ZIP或JAR。 5. **聚合与继承**:Maven支持项目聚合,一个父POM可以包含多个子...

    framework-maven-plugin:框架-maven-插件

    “框架-Maven-插件”通常会包含一些针对特定框架的构建、打包、部署等目标,例如Spring Boot的spring-boot-maven-plugin,它可以方便地对Spring Boot应用进行打包和运行。这类插件使得开发者无需深入理解框架内部的...

Global site tag (gtag.js) - Google Analytics