怎么样eclipse发达国家多重聚合关系maven项目和使用git管理
最近使用的项目的开发maven,多于maven有项目之间有一定的联系,因此,创建一个单独的,然后,maven聚合管理。
项目采用git要管理代码。由于上传的代码集时,.gitignore不要上传文件.setting其他文件,因此,git下载之后maven一个elipse项目文件。这样假设在github中拉下代码之后,再导入时不是非常方便。所以这里使用maven的插件,把各个项目变成Eclipse项目。
项目的结构例如以下:
当中encryption是多个maven项目中的当中一个,这些项目都依赖Utils4Java-parent中的pom文件
Utils4Java-parent:
encryption项目(新建的其它maven项目结构也如此):
在这里除了pom文件之外其它项目没有打勾,是由于用git上传到github时在.gitignore文件中被忽略掉了,而src没有被上传是由于目录中我没有加源代码,是空的。
在这里能够看到eclipse项目文件标志的.setting没有被上传。
在eclipse中导入是这种:
一.怎样用maven管理多个项目
Utils4Java-parent的pom文件例如以下。全部的maven项目的pom文件都依赖这个父文件:
<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.kxw</groupId>
<artifactId>Utils4Java-parent</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Utils4Java-parent</name>
<url>http://maven.apache.org</url>
<modules>
<module>../encryption</module>
</modules>
<profiles>
<profile>
<id>run_build</id>
<properties>
<log4j.print.sys>false</log4j.print.sys>
</properties>
</profile>
<profile>
<id>dev_build</id>
<properties>
<log4j.print.sys>true</log4j.print.sys>
</properties>
</profile>
</profiles>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://nexus.sourcesense.com/nexus/content/repositories/public/</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.10</junit.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showWarnings>true</showWarnings>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifestEntries>
<Vendor>${project.organization.name}</Vendor>
<Artifact-Id>${project.artifactId}</Artifact-Id>
<Implementation-Version>${project.version}</Implementation-Version>
<Build>${project.build}</Build>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
encryption项目中的pom文件例如以下:
<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> <parent> <groupId>com.kxw</groupId> <artifactId>Utils4Java-parent</artifactId> <version>0.0.1-SNAPSHOT</version> <relativePath>../Utils4Java-parent/pom.xml</relativePath> </parent> <artifactId>encryption</artifactId> <packaging>jar</packaging> <name>encryption</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> </dependencies> </project>
这样就能够在这基础上新建多个maven文件并依赖于父POM文件了。
二.用git管理项目代码
.gitignore文件:
.*.swp .DS_Store *target* *.jar *.war *.ear *.class classes/ .svn .classes .project .classpath .settings/ .metadata bin tmp/** tmp/**/* *.tmp *.bak *.swp *~.nib .classpath .settings/** tartget/** git.properties
想了解怎样用git上传代码能够看这里:http://blog.csdn.net/kingson_wu/article/details/38436923
三.使用maven插件把项目变成eclipse项目
这些插件在父POM文件已经配置。仅仅有执行MavenEclipseBuild.bat就可以
cd Utils4Java-parent call mvn eclipse:clean eclipse:eclipse pause
四.使用maven打包开发(測试)环境和正式环境
mavenProjectBuild.bat正式
cd Utils4Java-parent call mvn clean install -Dmaven.test.skip=true -Prun_build pause
mavenProjectBuild-Dev.bat开发
cd Utils4Java-parent call mvn clean install -Dmaven.test.skip=true -Pdev_build pause
parent的pom中:
<profiles>
<profile>
<id>run_build</id>
<properties>
<log4j.print.sys>false</log4j.print.sys>
</properties>
</profile>
<profile>
<id>dev_build</id>
<properties>
<log4j.print.sys>true</log4j.print.sys>
</properties>
</profile>
</profiles>
-------------
又一次pull代码之后
先project build
再Eclipse build
然后 project clean(在Eclipse中)
注意:切完 分支之会后再次eclipse.bat,否则,它是依赖于旧。
版权声明:本文博主原创文章。博客,未经同意不得转载。

浙公网安备 33010602011771号