maven package自动部署包

我们部署项目时经常会遇到打包部署工作(非web工程),那该如何配置pom.xml?请看如下配置

1.工程目录

2.pom配置

2.1  注意只需要配置pom中build节点就可以了。

    <build>
	<!-- 打包工程名称  -->
        <finalName>mafka-test</finalName>
	<!-- 拷贝所有依赖jar到部署工程目录下 -->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/${build.finalName}/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
	    <!-- 配置相关文件到部署目录下 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <encoding>UTF-8</encoding>
                            <outputDirectory>${basedir}/${build.finalName}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/resources/</directory>
                                    <includes>
                                        <include>*.*</include>
                                    </includes>
                                    <filtering>false</filtering>
                                </resource>
                                <resource>
                                    <directory>src/main/resources/config/</directory>
                                    <targetPath>${basedir}/${build.finalName}/config</targetPath>
                                    <includes>
                                        <include>*.*</include>
                                    </includes>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- 打jar包时需要把配置文件给排除在外 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <classifier>1.0</classifier>
                            <outputDirectory>${basedir}/${build.finalName}/lib</outputDirectory>
                            <excludes>
                                <exclude>*.xml</exclude>
                                <exclude>*.properties</exclude>
                            </excludes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>



3.构建结果

/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/bin/java -Dclassworlds.conf=/usr/local/Cellar/maven/3.2.1/libexec/bin/m2.conf -Dmaven.home=/usr/local/Cellar/maven/3.2.1/libexec -Didea.launcher.port=7543 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 12.app/bin" -Dfile.encoding=UTF-8 -classpath "/usr/local/Cellar/maven/3.2.1/libexec/boot/plexus-classworlds-2.5.1.jar:/Applications/IntelliJ IDEA 12.app/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher --no-plugin-registry --fail-fast --strict-checksums --update-snapshots -DskipTests=true package -P nexus,nexus-snapshots
[WARNING] Command line option -npr is deprecated and will be removed in future Maven versions.
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.meituan.mafka-test:mafka-test:jar:1.0-SNAPSHOT
[WARNING] ‘dependencies.dependency.(groupId:artifactId:type:classifier)‘ must be unique: junit:junit:jar -> version 4.7 vs 4.11 @ line 149, column 21
[WARNING] The expression ${build.finalName} is deprecated. Please use ${project.build.finalName} instead.
[WARNING] The expression ${build.finalName} is deprecated. Please use ${project.build.finalName} instead.
[WARNING] The expression ${build.finalName} is deprecated. Please use ${project.build.finalName} instead.
[WARNING] The expression ${build.finalName} is deprecated. Please use ${project.build.finalName} instead.
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mafka-test 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://nexus:8081/nexus/content/groups/public-snapshots/com/meituan/mtrace/mtrace/1.0.5-SNAPSHOT/maven-metadata.xml
Downloaded: http://nexus:8081/nexus/content/groups/public-snapshots/com/meituan/mtrace/mtrace/1.0.5-SNAPSHOT/maven-metadata.xml (361 B at 2.0 KB/sec)
Downloading: http://nexus:8081/nexus/content/groups/public-snapshots/com/meituan/mafka/client/mafka-client/1.0.0-SNAPSHOT/maven-metadata.xml
Downloaded: http://nexus:8081/nexus/content/groups/public-snapshots/com/meituan/mafka/client/mafka-client/1.0.0-SNAPSHOT/maven-metadata.xml (373 B at 3.5 KB/sec)
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ mafka-test ---
[debug] execute contextualize
[INFO] Using ‘UTF-8‘ encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ mafka-test ---
[INFO] Compiling 4 source files to /Users/lizhitao/mt_wp/test_wp/kafka-test/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ mafka-test ---
[debug] execute contextualize
[INFO] Using ‘UTF-8‘ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/lizhitao/mt_wp/test_wp/kafka-test/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ mafka-test ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ mafka-test ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ mafka-test ---
[INFO] Building jar: /Users/lizhitao/mt_wp/test_wp/kafka-test/target/mafka-test.jar
[INFO]
[INFO] --- maven-dependency-plugin:2.8:copy-dependencies (copy-dependencies) @ mafka-test ---
[INFO] Copying mafka-client-1.0.0-SNAPSHOT.jar to /Users/lizhitao/mt_wp/test_wp/kafka-test/mafka-test/lib/mafka-client-1.0.0-SNAPSHOT.jar
[INFO] Copying mtrace-1.0.5-SNAPSHOT.jar to /Users/lizhitao/mt_wp/test_wp/kafka-test/mafka-test/lib/mtrace-1.0.5-SNAPSHOT.jar
[INFO] core-3.1.1.jar already exists in destination.
[INFO] curator-framework-1.0.1.jar already exists in destination.
[INFO] oro-2.0.8.jar already exists in destination.
[INFO] commons-net-1.4.1.jar already exists in destination.
[INFO] netty-3.2.1.Final.jar already exists in destination.
[INFO] json-simple-1.1.jar already exists in destination.
[INFO] guava-10.0.1.jar already exists in destination.
[INFO] commons-logging-1.1.1.jar already exists in destination.
[INFO] commons-lang-2.6.jar already exists in destination.
[INFO] curator-client-1.0.1.jar already exists in destination.
[INFO] org.springframework.asm-3.1.1.RELEASE.jar already exists in destination.
[INFO] jsp-2.1-6.1.14.jar already exists in destination.
[INFO] scala-library-2.8.0.jar already exists in destination.
[INFO] commons-math-2.0.jar already exists in destination.
[INFO] jline-0.9.94.jar already exists in destination.
[INFO] org.springframework.beans-3.1.1.RELEASE.jar already exists in destination.
[INFO] commons-httpclient-3.1.jar already exists in destination.
[INFO] jopt-simple-4.3.jar already exists in destination.
[INFO] jackson-mapper-asl-1.5.5.jar already exists in destination.
[INFO] metrics-annotation-2.2.0.jar already exists in destination.
[INFO] xmlenc-0.52.jar already exists in destination.
[INFO] jets3t-0.7.1.jar already exists in destination.
[INFO] jetty-util-6.1.14.jar already exists in destination.
[INFO] pig-0.8.0.jar already exists in destination.
[INFO] metrics-core-2.2.0.jar already exists in destination.
[INFO] kafka_2.10-0.8.1.jar already exists in destination.
[INFO] commons-cli-1.2.jar already exists in destination.
[INFO] jackson-core-asl-1.5.5.jar already exists in destination.
[INFO] hsqldb-1.8.0.10.jar already exists in destination.
[INFO] zookeeper-3.3.3.jar already exists in destination.
[INFO] hadoop-core-0.20.2.jar already exists in destination.
[INFO] junit-4.11.jar already exists in destination.
[INFO] paranamer-2.2.jar already exists in destination.
[INFO] jsr305-1.3.9.jar already exists in destination.
[INFO] log4j-1.2.16.jar already exists in destination.
[INFO] servlet-api-2.5-6.1.14.jar already exists in destination.
[INFO] paranamer-ant-2.2.jar already exists in destination.
[INFO] kafka_2.8.0-0.8.1.jar already exists in destination.
[INFO] snappy-java-1.0.5.jar already exists in destination.
[INFO] kafka-hadoop-consumer-0.8.1.jar already exists in destination.
[INFO] org.json.simple-0.3-incubating.jar already exists in destination.
[INFO] jsp-api-2.1-6.1.14.jar already exists in destination.
[INFO] hamcrest-core-1.3.jar already exists in destination.
[INFO] jasper-compiler-5.5.12.jar already exists in destination.
[INFO] kfs-0.3.jar already exists in destination.
[INFO] jasper-runtime-5.5.12.jar already exists in destination.
[INFO] commons-codec-1.4.jar already exists in destination.
[INFO] commons-collections-3.2.1.jar already exists in destination.
[INFO] asm-3.2.jar already exists in destination.
[INFO] jetty-6.1.14.jar already exists in destination.
[INFO] zkclient-0.3.jar already exists in destination.
[INFO] qdox-1.10.1.jar already exists in destination.
[INFO] velocity-1.6.4.jar already exists in destination.
[INFO] avro-1.4.0.jar already exists in destination.
[INFO] ant-1.7.1.jar already exists in destination.
[INFO] ant-launcher-1.7.1.jar already exists in destination.
[INFO] paranamer-generator-2.2.jar already exists in destination.
[INFO] avro-1.3.2.jar already exists in destination.
[INFO] curator-test-1.0.1.jar already exists in destination.
[INFO] service-common-mtzkclient-1.6.1.jar already exists in destination.
[INFO] slf4j-api-1.6.1.jar already exists in destination.
[INFO] slf4j-log4j12-1.6.1.jar already exists in destination.
[INFO] commons-el-1.0.jar already exists in destination.
[INFO] ant-1.6.5.jar already exists in destination.
[INFO] org.springframework.core-3.1.1.RELEASE.jar already exists in destination.
[INFO] javassist-3.15.0-GA.jar already exists in destination.
[INFO] curator-recipes-1.0.1.jar already exists in destination.
[INFO]
[INFO] --- maven-resources-plugin:2.5:copy-resources (copy-resources) @ mafka-test ---
[debug] execute contextualize
[INFO] Using ‘UTF-8‘ encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 2 resources to /Users/lizhitao/mt_wp/test_wp/kafka-test/mafka-test/config
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default) @ mafka-test ---
[INFO] Building jar: /Users/lizhitao/mt_wp/test_wp/kafka-test/mafka-test/lib/mafka-test-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.871 s
[INFO] Finished at: 2014-05-14T14:41:53+08:00
[INFO] Final Memory: 25M/228M
[INFO] ------------------------------------------------------------------------

如下图:

maven package自动部署包,布布扣,bubuko.com

时间: 2024-10-07 05:45:48

maven package自动部署包的相关文章

Maven Tomcat7自动部署

林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文主要讲了Maven中使用Tomcat7进行自动部署,其中maven多模块web项目看这里看我的另一博文http://blog.csdn.net/evankaka/article/details/46730401 1.配置tomcat-users.xml文件 在tomcat安装目录下找到tomcat-users.xml文件.该文件路径为[tomcat安装根目录]/conf/ 修改文件

使用maven插件自动部署web应用至Docker容器的tomcat

配置maven 在pom.xml加入 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 <plugins>     <plugin>         <groupId>org.apache.tomcat.maven</groupId>         <artifactId>tomcat7-maven-plugin</artifactId>         <version>2.2</version&g

(转)maven自动部署web项目到tomcat8(向下兼容7)

maven自动部署web项目到tomcat8(向下兼容7) 2014-08-29 10:52 网站上线以后,为了保证网站运行的连续性,有新功能更新时,不能重启Tomcat服务器去部署新增功能.因此,就研 究一下用maven的自动部署功能. 1首先要保证自己电脑上装了Tomcat服务器 进入Tomcat安装目录,打开..\conf\tomcat-users.xml,在这个配置文件中加入以下内容: <role rolename="manager-gui"/> <role

使用Maven自动部署Java Web项目到Tomcat问题小记

导读 首先说说自己为啥要用maven管理项目,一个直接的原因是:我在自己电脑上开发web项目,每次部署到服务器上时都要经历如下步骤: 首先在Eclipse里将项目打包成war包 将服务器上原来的项目文件夹删掉 cd /var/lib/tomcat7/webapps sudo rm XXX.war sudo rm -rf XXX 将war包传到服务器上,比如用pscp命令上传 pscp -pw "xxx" XXX.war [email protected]:/var/lib/tomcat

maven自动部署web项目到tomcat8(向下兼容7)

网站上线以后,为了保证网站运行的连续性,有新功能更新时,不能重启Tomcat服务器去部署新增功能.因此,就研 究一下用maven的自动部署功能. 1首先要保证自己电脑上装了Tomcat服务器 进入Tomcat安装目录,打开..\conf\tomcat-users.xml,在这个配置文件中加入以下内容: <role rolename="manager-gui"/> <role rolename="manager-script"/> <us

maven自动部署到远程tomcat教程

使用maven的自动部署功能可以很方便的将maven工程自动部署到远程tomcat服务器,节省了大量时间. 本文章适用于tomcat的7.x ,8.x, 9.x版本. 下面是自动部的步骤 1,首先,配置tomcat的manager 编辑远程tomcat服务器下的conf/tomcat-users.xml,在末尾增加(其实只要拉到文件末尾,去掉注释改一下就可以了) <role rolename="manager-gui"/> <role rolename="m

在Eclipse中使用Maven将Web项目自动部署到tomcat服务器

一.创建Web项目 1.1 选择建立Maven Project 选择File -> New ->Project,如下图所示: 在New窗口中选择 Maven -> Maven Project.点击[next]如下图所示: 1.2 选择项目路径 根据项目的实际情况选择项目的存放目录,也可以选择[Use default Workspace location]默认工作空间.如下图所示: 1.3 选择项目类型 在Artifact Id中选择maven-archetype-webapp,如下图所示

maven自动部署项目以及常见问题解决

Maven自动部署war到Tomcat1. 在maven项目的pom里配置如下信息 <build> <finalName>dianxiao</finalName> <!-- WAR包的名字 --> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId

Maven学习教程(七)------将web项目自动部署到tomcat下

一.创建Web项目 1.1 选择建立Maven Project 选择File -> New ->Maven Project,如下图所示: 点击[next]如下图所示: 选择webapp,点击[next]如下图所示: 输入Group ID和 Artifact ID以及Package Group ID一般写大项目名称.Artifact ID是子项目名称. 例如Spring的web包,Group ID:org.springframework,artifactId:spring-web. Packag