Using multiple source folders (as an intermediate step when converting a large Java project to Maven)

I am converting a large Java project to use maven. I have many interdependencies to work, but I would like to get it from scratch with maven before I do the real work of cleaning. I broke it into several modules plus one giant module; let me call this module monolith. The monolith has the usual Java classes and some gwt classes (with interdependencies). I divided the two parts to have a directory structure like this:

./SRc/home/Java / ...
./src/client/gwt / ...

So, I can easily get this to compile in eclipse with m2eclipse, but then I cannot find how it can be compiled using maven. I saw that there is an assembly section in the pom file where you can specify an alternative source and target, but I think this is not a repeatable attribute in pom:

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

In eclipse, I can configure the .classpath project file (in the project properties) to add additional source files (and output dirs) to accomplish what I'm looking for.

Is there a way to do this, or do I need to develop the dependencies first, and split them into separate modules?

+4
source share
3 answers

If you go against the grain with maven, it will be a tough battle all the way.
Maven is not inclined to several main source directories, they will work better in the maven environment as separate modules.
I reviewed a number of maven maven projects and archetypes, and none of them seemed to use the approach you suggested.
Look at the source structure used by Hupa , also see Archetypes from the Ham and Eggs Blog

They also serve the App Engine.

If you really need to separate your java server source from your gwt client source, then the monolith needs to be divided into several modules.
Typically, common gwt projects with a package structure look like this:

 com.company.project .client .server .shared 

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

+5
source

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

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

β€œI'm not sure what you meant.” The M2Eclipse plugin uses maven to create your modules. Perhaps you can clarify this section. We hope that the tutorial link will help you.

+5
source

try following this guide http://maven.apache.org/plugins/maven-eclipse-plugin/reactor.html The basic idea is to start by creating an empty project from maven mvn archetype: create and then add sources created by the maven structure .. also I can highly recommend checking your dependency tree and efficient pom with the eclipse plugin tool when you do this task (to avoid duplication in the folder and other bad things)

+1
source

Source: https://habr.com/ru/post/1343054/


All Articles