0

I have two mavenized projects

  1. Project_A: Java Project
  2. Project_B: Java Web Project

Earlier, before mavenizing both projects, i had refrence(buildpath) of Project_A in Project_B. Now i have configured both projects with maven2. MY questions is, how can i add a refrence of Project_A in Project_B that WAR of Project_B can be runnable

so far i have tried following chunk of code which seems to work but on runtime Project_B's WAR throw an exception in applicationContext that an Instance of Project_A's class cannot be initiated.

1- Project_A is cleaned and installed in local repository with name "myproject-1.0.jar" where build snippet(Project_A's POM) is as follows#

Edited Part

  <modelVersion>4.0.0</modelVersion>
   <groupId>org.myurl<groupId>
<artifactId>projectA</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>${project.artifactId}-${project.version}</name>




build>
        <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
        <outputDirectory>${basedir}/target/classes</outputDirectory>
        <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
        <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>${basedir}/src/test/resources</directory>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <optimize>true</optimize>
                </configuration>
            </plugin>

        </plugins>
    </build>
  1. Snippet of Project_B's POM, where i am adding installed jar of Project_A

             <dependency>
        <groupId>org.myurl</groupId>
        <artifactId>projectA</artifactId>
        <version>1.0</version>
        <scope>compile</scope>
    </dependency>
    

Thanks for suggestions in advance.

Answer : Actually there was not any problem with maven. Above configurations in POM are absolutely correct. I had moved properties files under /Resources and later i have forgotten to change paths in those classed where properties files are utilized.

Nevertheless i am thankful to Dolphin and Nicola Musatti for their suggestions.

Rehman
  • 3,908
  • 6
  • 28
  • 29
  • It sounds like maybe the problem is that the classes from project A are not included in the generated project B war? Are they? – PapaFreud Oct 31 '11 at 09:36
  • if i browse deploy folder of jboss Server, i can easily find all generated classes of Project_A WEB_INF of PRoject_B's Webapp – Rehman Oct 31 '11 at 09:51

1 Answers1

0

You are on good way, pom snippet is fine what you need to do now is make parent project (Maven Reactor). So you will make new project and in that project define modules (Project A and Project B). You will reference that parent in Project A and Project B, and that will do the trick. Google maven parent to see how it's done.

After building Project B, maven will first build Project A and after that Project B.

Thing is your approach should work as well (just it's not a proper way to do it). So probably you are making mistake in groupId, version. You can check this by build Project A and then checking your local maven repository. Inside of it you should see folder structure if not something went wrong.

org/myurl/projectA-1.0.jar

Project strucuture is following:

project-parent project-a project-b

in project parent you define:

<groupId>foo.bar</groupId>
<artifactId>project-parent</artifactId>
<version>00.01-SNAPSHOT</version>
<name>FooBar:: Parent Project</name>
<packaging>pom</packaging>

<modules>
    <module>../project-a</module>
    <module>../project-b</module>
</modules>

in project-a and project-b you add:

<parent>
    <groupId>foo.bar</groupId>
    <artifactId>project-parent</artifactId>
    <version>00.01-SNAPSHOT</version>
</parent>

In project-b you will have reference to project-a

    <dependency>
        <groupId>foo.bar</groupId>
        <artifactId>project-a</artifactId>
        <version>00.01-SNAPSHOT</version>
    </dependency>

Once you build parent it should build all modules correctly. Don't use plugin, forget I said Maven Reactor :)

Haris Krajina
  • 14,824
  • 12
  • 64
  • 81
  • i have edited snippet of Project_A's pom and under my local maven repository i can see projectA-1.0.jar – Rehman Oct 31 '11 at 09:54
  • i have googled but unable to pick that how can i use it. so far i have tried to put maven maven-reactor-plugin 1.0 . and after that i tried to do mvn install but still war do not run properly. Moreover, i am using myeclipse. further assistance would be highly appreciated – Rehman Oct 31 '11 at 10:40
  • Ok I will Add example in my answer. – Haris Krajina Oct 31 '11 at 11:21
  • Here is explanation: http://stackoverflow.com/questions/2050241/what-is-the-maven-reactor Most of the reactor plugin features are now natively supported (since Maven 2.1.0). So when you are doing parent/module relationship you are utilizing maven reactor pattern. – Haris Krajina Oct 31 '11 at 11:30
  • What you're using here is actually an aggregator and not a parent project. These are different concepts, even if the official documentation is misleading on this subject, unfortunately. Aggregation helps build projects at the same time by means of the reactor, while a parent project's purpose is to share settings among related projects. project-a and project-b don't need to have project-parent to be specified as their parent, and it's actually a bad idea to do so. – Nicola Musatti Oct 31 '11 at 13:48
  • But if you do not link projects via parent, they will not be aggregated (built) properly. Meaning if you build project-b, project-a build will not be triggered. – Haris Krajina Oct 31 '11 at 14:02