Although it might be considered as bad practice I ran into a case in which I wanted to add an extra source path to my Maven build besides the default ‘/src/main/java’ path. In my situation I generate Java code with JAX-WS to create a web service based on an existing WSDL (I will show this in a separate post). Normally you generate this code in the ‘target’ folder so it is automatically build up in the compile step and cleaned up in the clean step. But like I said I wanted to be able to use the generated code in my Netbeans project as ‘source’ code but I did not want mix it with my own code.
So I added an extra source path as described in this post like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ... <!-- Plugin to add source path to build cycle --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>${basedir}/generated/src/main/java</source> </sources> </configuration> </execution> </executions> </plugin> ... |
And to keep it clean I also added the generated source path to the ‘clean plugin’ like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | ... <!-- Plugin to add delete path to build cycle --> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>2.2</version> <configuration> <filesets> <fileset> <directory>generated/src/main/java</directory> <includes> <include>**/*.java</include> </includes> </fileset> </filesets> </configuration> </plugin> ... |
This configuration makes it possible to use the extra source path as a normal Maven path and it shows up nicely in my Netbeans project:

Pingback: 'Hello World' with Glassfish, Metro and Maven | Redstream Blog
Pingback: 'Hello World' with Glassfish, Metro and Maven | Redstream Blog