0

I have two GAE Java projects, A and B. I want to use some of the mature classes from A in B (and continue to use them in A too, of course). Both projects were created using maven and then imported into Eclipse (in my mind, this kinda makes maven primary and Eclipse secondary :-).

What is the best way to do this, keeping maven primary?

I expect the solution will be something like:

  • Create a new maven project C.
  • Move the common classes to C.
  • Include C as dependency in pom.xml of A and B (possible to do this without first exporting C as a jar?).

Hopefully after this I will be able to run and test (mostly done by running mvn appengine:devserver) A and B independent of each other.

My knowledge of maven is limited, so how do I create (e.g., which archetype to use) this project C such that:

  • it will import successfully as an independent Eclipse project,
  • be export-able as a jar (if need be), and,
  • trigger re-build of A and B when C changes, whether it is Eclipse auto-recompiling or maven recompiling when I run mvn appengine:devserver

If there is a better but completely different solution, I wouldn't mind considering that too.

Configuration:

  • OS: OS X 10.9.5
  • maven: 3.1.1
  • Eclipse: Kepler (4.3) with m2eclipse
  • Java: 1.7.0_45

Thanks!!

markvgti
  • 4,321
  • 7
  • 40
  • 62

2 Answers2

1

Well, you are very close to the "good and right" solution. You write it in your question :-)

  • Create a new maven project C.
  • Move the common classes to C. Build (mvn clean install) project C. As a result, the JAR will be in your local repo.
  • Now you can include C as dependency in pom.xml of A and B.

Note that as you have mentioned, if there is any change in project C, projects A+B will have to be re-compiled.

Of course, C.JAR is ready for use and there it is not related to any IDE such as Eclipse.

OhadR
  • 8,276
  • 3
  • 47
  • 53
1

Regarding which archetype to use, you can use maven quickstart archetype:

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart

from : https://maven.apache.org/archetype/maven-archetype-bundles/maven-archetype-quickstart/