maven是一个优秀的项目管理工具。目前市面上优秀的书籍就是《maven实战》。
依旧不能解决问题:
1.maven内置变量
Maven内置变量说明:
${basedir} 项目根目录
${project.build.directory} 构建目录,缺省为target
${project.build.outputDirectory} 构建过程输出目录,缺省为target/classes
${project.build.finalName} 产出物名称,缺省为${project.artifactId}-${project.version} 当前版本
${project.packaging} 打包类型,缺省为jar
${project.xxx} 当前pom文件的任意节点的内容java
<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>cn.com.travelman</groupId> <artifactId>CommonRestService</artifactId> <version>0.0.1-SNAPSHOT</version> <name>RestService</name> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>ServiceData</artifactId> <version>${project.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>cn.com.travelman.service.rest.publish.Server</mainClass> </manifest> </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> <outputDirectory>${project.build.directory}/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
maven一个重要的特色就是:能够将classpath路径的值写入jar的MF文件中。这样就能够直接运行jar文件。
使用maven-jar-plugin能够作到这一点。 <addClasspath>true</addClasspath>就表示将依赖的包路径写入到MF文件中。但要注意,写入的classpath只是包的名字,因此运行的JAR包要和lib包要在同一个目录下。apache
maven能够在一个工程里面引入另一个工程:maven
<dependency> <groupId>${project.groupId}</groupId> <artifactId>ServiceData</artifactId> <version>${project.version}</version> </dependency>
没错,artifactId就是你另一个工程的artifactId。这样比起使用java build path去引用是否是牛逼方便不少?工具
而且用maven-dependency-plugin将这些包导出到指定的目录中间。ui
此外,去 http://mvnrepository.com/搜索想要的包的配置。spa
另一个问题:这些搜索出来的配置并非你想要的配置。好比搜索 apache cxf。
这个时候去官网下载sample,找里面的POM文件配置。rest
如何给maven配置多个源文件:
http://casheen.iteye.com/blog/540385code