Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using multiple source folders (as intermediate step in a conversion of a large Java project to Maven)

I am converting a large Java project to use maven. I have a LOT of inter dependencies to work out, but I would like to get it off the ground with maven before I do the real cleanup work. I have broken it up into a few modules plus one giant module; let's call that module monolith. Monolith has regular Java classes and some gwt classes (with interdependencies). I separated the two parts to have a directory structure like this:

./src/main/java/...
./src/client/gwt/...

So, I can easily get this to compile in eclipse with m2eclipse, but then I can't seem to find how to get it to compile with maven. I saw that the pom file has a build section where you can specify an alternate source and target, but I think it is not a repeatable attribute in the pom:

<build>
    <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
</build>

In eclipse, I can adjust the project's .classpath file (in the project properties) to add additional source files (and output dirs) to accomplish what I am looking to do.

Is there any way to do this, or do I need to work out the dependencies first, and separate into separate modules?

like image 352
Mike Avatar asked Dec 21 '22 16:12

Mike


2 Answers

If you go against the grain with maven it will be an uphill battle all the way.
Maven doesn't lean towards multiple main source directories, they would do better in maven environment as separate modules.
I've looked at a number of maven gwt projects and archetypes, and none of them seem to take the approach you've suggested.
Have a look at the source structure used by Hupa, also see the archetypes from the Ham and Eggs blog

  • http://hamandeggs.wordpress.com/2010/01/26/how-to-gae-eclipse-maven/
  • http://hamandeggs.wordpress.com/2010/07/25/gae-eclipse-maven-update-for-helios/

These also cater for App Engine.

If you really need to separate your java server source from your gwt client source, then monolith needs to be split into more modules.
It is quite common to see gwt projects with a package structure as follows:

com.company.project
                   .client
                   .server
                   .shared

And then specify the source paths in your gwt.xml to include client and shared

like image 164
crowne Avatar answered Apr 29 '23 22:04

crowne


What you have is called a maven multi-module project. Take a look at this tutorial on the maven book.

So, I can easily get this to compile in eclipse with m2eclipse, but then I can't seem to find how to get it to compile with maven.

-- I am not sure what you meant by this. M2Eclipse plugin is using maven to build your modules. Perhaps you can clarify this section. Hope the tutorial link helps you.

like image 22
CoolBeans Avatar answered Apr 29 '23 20:04

CoolBeans