In addition to the src/main/java, I am adding a src/bootstrap directory that I want to include in my build process, in other words, I want maven to compile and include the sources there in my build. How!?
Simple question: Why not moving the source code to src/main/java ? Or create a separate maven project/module which contains the code and define it as dependency.
– khmarbaiseMar 17 '12 at 21:14
7
In my case I need to add a generated sources folder, which I prefer to reside inside target.
– djjeckJul 10 '13 at 21:02
Alternatively, one might want to place *integration-tests* in directories other than `src/{main,test}/` as told [here](https://dzone.com/articles/integration-tests-with-maven)
– y2k-shubhamAug 21 '18 at 07:57
This has also been discussed here: https://stackoverflow.com/q/270445/1061929
– bjmiFeb 09 '20 at 09:38
Does eclipse really recognize such a folder as one of the `buildpath`s for anyone? 'cos it doesn't for me. FWIW, I use `m2e` to import the project.
– mystarrocksOct 30 '14 at 13:21
Great answer, just to clarify, you should replace your maven-compiler-plugin with the lines from above...
– ColinNov 04 '14 at 16:11
So if (in Eclipse Luna) i added (linked) in my BuildPath (clicking the right mouse button on my MavenProject) a source folder where its directory is "/Users/MyName/Desktop/source", i have to write `/Users/MyName/Desktop/source` ?? And everything goes right?
– AeroxApr 29 '15 at 18:07
I don't know why, but i simply removed the linked source and re-added on the build path and everything has gone right. If I have any other problem I will post that here. Thanks anyway :-)
– AeroxMay 03 '15 at 22:08
The question is about Maven, which has no knowledge of (nor should it) of the IDE (e.g., eclipse). Builds should work on Jenkins or whatever build server without any IDE-specific references. The IDE must invoke Maven (build tool) and thus IDE-related questions should probably be taken out separately.
– Darrell TeagueJan 21 '16 at 19:02
1
Eclipse asked me to install a plugin for m2e, the build helper connector. I did it, and the lifecycle error is gone.
– Alexis DufrenoyFeb 01 '16 at 16:42
This requires me to move to java 7, this solution does not work for java 6 ?
Or am I missing something ?
– MithunSFeb 24 '16 at 22:59
In Eclipse, when you add a resource like this, you need to remove the ** exclusion from the build path for the directory to have it recognize the sources.
– DormouseJan 08 '14 at 12:51
2
Does not work with IntelliJ, it will see `` as "Resource" folder but not as "Source" folder, e.g. it won't compile Java source files inside them.
– Alexander KlimetschekDec 20 '14 at 01:42
I was referring to IntelliJ's Maven support that reads pom files automatically and sets its projects settings accordingly - it will strictly see `` folders as resource directories, not sources.
– Alexander KlimetschekDec 23 '14 at 09:38
9
This solution will just move the java source files to the target/classes directory and will *not compile* the sources
– Stefan HaberlFeb 05 '15 at 11:14
This overrides the default src/main/java directory. If you want multiple directories, you have to specify the default one as well.
– NatixDec 09 '15 at 14:16
6
The question is how to add multiple source directories and you are proposing a method to add only one source directory, which is the opposite of what is asked.
– João MatosOct 03 '16 at 13:56
2
To mark a folder as generated sources, AND have it picked up by IntelliJ, use the following:
I spent an hour searching on how to avoid IntelliJ reverting after I manually marked target/generated-sources as a generated sources folder. The codehaus.mojo plugin didn't work. But this solution did!
This is exactly what was required for me. I am working with protobuf and it defaults its compiled code in generatedSource dir. For some reason intellij, doesnt implicitly pick the class def files for me to use them in core app class files. I had to give the above plugin to make it look into the target folder. Thanks for this solution. It made a quick work.
– Sunil K-Standard CharteredMar 19 '23 at 16:33
1
Seems to be the most correct solution. In my case `generatedSourcesDirectory` is `target/generated-sources`.
– AndreyAug 15 '23 at 11:58
1
With recent Maven versions (3) and recent version of the maven compiler plugin (3.7.0), I notice that adding a source folder with the build-helper-maven-plugin is not required if the folder that contains the source code to add in the build is located in the target folder or a subfolder of it.
It seems that the compiler maven plugin compiles any java source code located inside this folder whatever the directory that contains them.
For example having some (generated or no) source code in target/a, target/generated-source/foo will be compiled and added in the outputDirectory : target/classes.
Why the downvotes people? Basically the same answer as saiky0's (which has upvotes) but earlier?
– FrisoJan 26 '15 at 10:24
16
@Friso because it's not correct. Adding a resource directory will add resources (files copied to `target/classes`, but not compiled). This question is about adding a source directory, which holds files that will be *compiled* into `target/classes`, not copied.
– Darth AndroidMay 26 '15 at 20:39