java - Maven 2 Projects -


i have 2 projects

  1. sever side project crud operations. (lets p1)
  2. client side jsf presentation layer java web project. (p2)

since p2 depend upon entities in p1, have included p1 in build path of p2. (not through maven)

everytime make changes p1, have export jar , place in tomcat webapp folder, else throw noclassdef.

can automated?

you can build main maven project has 3 submodules, master, platform , parent.

(note: following projects should set gav parameters consistently application architecture, in order have significant names easy understand)

the main project has order in other projects evaluated maven:

<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.acme.projects</groupid>   <artifactid>main</artifactid>   <version>0.0.1-snapshot</version>   <packaging>pom</packaging>    <properties>     <project.build.sourceencoding>utf-8</project.build.sourceencoding>   </properties>    <build>         <plugins>             <plugin>                  ....             </plugin>         </plugins>     </build>  <modules>     <module>master</module>     <module>parent</module>     <module>platform</module> </modules> 

the master pom contains list of project built , order (aka reactor order)

<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.acme.projects</groupid>       <artifactid>master</artifactid>       <version>0.0.1-snapshot</version>       <packaging>pom</packaging>      <modules>         <module>../../p1</module>         <module>../../p2</module>            </modules> </project> 

as can see p2 must inserted after p1, since p2 has p1 dependency.

the platform pom contains information platform, jdk version, maven plugin versions, encoding , on.

<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.acme.projects</groupid>     <artifactid>platform</artifactid>     <version>0.0.1-snapshot</version>     <packaging>pom</packaging>      <build>         <pluginmanagement>             <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>                         <encoding>utf-8</encoding>                     </configuration>                 </plugin>                  <plugin>                     <groupid>org.apache.maven.plugins</groupid>                     <artifactid>maven-install-plugin</artifactid>                     <version>2.3.1</version>                 </plugin>                  <plugin>                     <groupid>org.apache.maven.plugins</groupid>                     <artifactid>maven-jarsigner-plugin</artifactid>                     <version>1.2</version>                 </plugin>                 <plugin>                 .....                 </plugin>             </plugins>          </pluginmanagement>     </build>  </project> 

the parent pom has platform pom parent , contains global gav information dependencies going use in project (spring, cxf, junit, log4j etc.)

<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>     <parent>         <groupid>com.acme.projects</groupid>         <artifactid>platform</artifactid>         <version>0.0.1-snapshot</version>         <relativepath>../platform</relativepath>     </parent>      <artifactid>parent</artifactid>     <packaging>pom</packaging>     <groupid>com.acme.projects</groupid>      <properties>         <project.build.sourceencoding>utf-8</project.build.sourceencoding>             <spring.version>4.1.6.release</spring.version>         <!-- == web services == -->         <cxf.version>3.0.4</cxf.version>         <!-- == testing == -->         <junit.version>4.12</junit.version>     </properties>      <dependencymanagement>         <dependencies>              <!-- == logging == -->             <dependency>             <groupid>log4j</groupid>             <artifactid>log4j</artifactid>             <version>1.2.17</version>         </dependency>              <!-- == spring == -->             <dependency>                 <groupid>org.springframework</groupid>                 <artifactid>spring-context</artifactid>                 <version>${spring.version}</version>             </dependency>             <dependency>                 <groupid>org.springframework</groupid>                 <artifactid>spring-aop</artifactid>                 <version>${spring.version}</version>             </dependency>             <dependency>                 <groupid>org.springframework</groupid>                 <artifactid>spring-tx</artifactid>                 <version>${spring.version}</version>             </dependency>             <dependency>                 <groupid>org.springframework</groupid>                 <artifactid>spring-jdbc</artifactid>                 <version>${spring.version}</version>             </dependency>             <dependency>                 <groupid>org.springframework</groupid>                 <artifactid>spring-context-support</artifactid>                 <version>${spring.version}</version>             </dependency>             <dependency>                 <groupid>org.springframework</groupid>                 <artifactid>spring-test</artifactid>                 <version>${spring.version}</version>                 <scope>test</scope>             </dependency>               <dependency>                 <groupid>junit</groupid>                 <artifactid>junit</artifactid>                 <version>${junit.version}</version>                 <scope>test</scope>             </dependency>         </dependencies>     </dependencymanagement> </project> 

finally have project structure this:

projects structure

and have put right pom inside each project folder. now, both p1 , p2 projects must have parent project parent, , p2 must have dependency p1.

in order have whole reactor built, have set main directory , use command

mvn clean install 

which compile p1 project , make available dependency p2 project.

this approach has many advantages:

  1. you can add more projects list , have them automatically compiled without worrying placing jars around (every new project must have parent parent)
  2. make easier automate process ci tools jenkins, have compiling process under control
  3. concentrate dependencies version @ top of hierarchy , specialize in subproject needed

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -