maven build脚本笔记

如果 code 只存在src/java/main 路径下,直接install就好,不必写<build>

资源文件:edu-common-config

<build>
        <finalName>edu-common-config</finalName>
        <resources>
            <!-- 指定 src/main/resources下所有文件及文件夹为资源文件 -->
            <resource>
                <directory>src/main/resources</directory>
                            <targetPath>${project.build.directory}/classes</targetPath>
                <includes>
                    <include>**/*</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

finalName: 生成最后的文件的样式
resources: resource的列表,用于包括所有的资源
targetPath: 指定目标路径,需要打包的目标文件路径,用于build
filtering: 是否替换资源中的属性placehold
directory: 资源所在的位置
includes: 样式,包括那些资源
excludes: 排除的资源
testResources: 测试资源列表
Web项目打成可执行jar文件,包含外部lib,build脚本

<build>
		<finalName>edu-dubbo-service</finalName>

		<resources>
			<resource>
				<targetPath>${project.build.directory}/classes</targetPath>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
				<includes>
					<include>**/*.xml</include>
					<include>**/*.properties</include>
				</includes>
			</resource>
			<!-- 结合com.alibaba.dubbo.container.Main -->
			<resource>
				<targetPath>${project.build.directory}/classes/META-INF/spring</targetPath>
				<directory>src/main/resources/spring</directory>
				<filtering>true</filtering>
				<includes>
					<include>spring-mybatis.xml</include>
				</includes>
			</resource>
		</resources>

		<pluginManagement>
			<plugins>
				<!-- 解决Maven插件在Eclipse内执行了一系列的生命周期引起冲突 -->
				<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>
										</goals>
									</pluginExecutionFilter>
									<action>
										<ignore />
									</action>
								</pluginExecution>
							</pluginExecutions>
						</lifecycleMappingMetadata>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>
		<plugins>
			<!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<classesDirectory>target/classes/</classesDirectory>
					<archive>
						<manifest>
							<mainClass>com.alibaba.dubbo.container.Main</mainClass>
							<!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
							<useUniqueVersions>false</useUniqueVersions>
							<addClasspath>true</addClasspath>
							<classpathPrefix>lib/</classpathPrefix>
						</manifest>
						<manifestEntries>
							<Class-Path>.</Class-Path>
						</manifestEntries>
					</archive>
				</configuration>
			</plugin>
			<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>
							<type>jar</type>
							<includeTypes>jar</includeTypes>
							<useUniqueVersions>false</useUniqueVersions>
							<outputDirectory>
								${project.build.directory}/lib
							</outputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>

	</build>

  

web:

<build>
        <finalName>edu-dubbo-web</finalName>
        <resources>
            <resource>
                <targetPath>${project.build.directory}/classes</targetPath>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
        <!-- 解决“Dynamic Web Module 3.0 requires Java 1.6 or newer.”错误 -->
         <plugins>
            <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>
                </configuration>
            </plugin>
        </plugins>
    </build>
时间: 2024-10-04 13:46:57

maven build脚本笔记的相关文章

[转载]Maven初级入门笔记

最近在研究Maven,写了一个简单的学习笔记. 本文所有资料百度云地址:http://pan.baidu.com/s/1jGn27PG 首先需要在本机上搭建一个nexus私服. 第一步,将Maven总结资料\工具目录下的nexus-2.1.2.war直接放在D:\Tomcat 7.0\webapps目录下. 第二步,启动tomcat后,在webapps目录下生成一个nexus-2.1.2目录. 第三步,停掉tomcat,修改nexus-2.1.2目录名称为nexus.再次启动tomcat,访问h

在eclipse如何删除无效的maven build

在Eclipse的maven项目中,点击一次“maven build...”明明没有配置,它也就会产生一个maven build,那么如何删除这些无效的配置呢?

eclipse中使用maven插件的时候,运行run as maven build的时候报错

eclipse中使用maven插件的时候,运行run as maven build的时候报错. 问题是因为,eclipse和Maven不兼容导致的.用eclipse自带的即可.自带的版本低.要是使用高版本的,请按照如下的步骤配置一下即可. -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match. 可以设一个环境变量

maven:log4j:WARN No appenders could be found for logger (loggerInfo).或者maven build error:org.apache.maven.lifecycle.LifecycleExecutionExceptio

maven在build构建时,加载资源文件时需要配置资源文件插件: 1,在pom.xml文件中加入 <build> <finalName>${project.build.target.file.name}</finalName> <directory>${basedir}/target</directory>  <sourceDirectory>${basedir}/src/main/java</sourceDirectory&

maven build 产生 Missing artifact org.jboss.logging:jar:3.1.0.GA解决方法

报错来源分析 由于hibernate-entitymanager 需要jboss logging .由于或多或少的原因导致 maven无法下载相关的jar文件. 解决办法: 访问 http://search.maven.org 搜索jboss-logging 点击all, 找到相关的的版本,再点击jar下载文件 下载好的文件放到maven仓库中对应版本的位置,一般是C:\Users\ username \ .m2\repository\org\jboss\logging\jboss-loggin

Maven Build Profiles--reference

What is Build Profile? A Build profile is a set of configuration values which can be used to set or override default values of Maven build. Using a build profile, you can customize build for different environments such asProduction v/s Development en

学习shell脚本笔记

1.if 是单分支语句,使用格式如下: if condition ; then statement -.. fi 2.if - else 是双分支语句,使用格式如下: if condition ; then statement -. else statement -. fi 3.if -elif-elif-else 是多分支语句,使用格式如下: if condition ; then statement -. elif condition ; then statement -.. elif co

Android SDK Tools 24.3.2 Build脚本Bug

如下图版本: 在%Android_home%\tools\ant\build.xml中, 在483行附近, 少了aidl,aapt,dx, zipalign四个变量的声明. 加上就OK了. <property name="aidl" location="${android.build.tools.dir}/aidl${exe}" /> <property name="aapt" location="${android.

Maven Build Life Cycle--reference

What is Build Lifecycle? A Build Lifecycle is a well defined sequence of phases which define the order in which the goals are to be executed. Here phase represents a stage in life cycle. As an example, a typical Maven Build Lifecycle is consists of f