Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an extra source directory for maven to compile and include in the build jar?

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!?

like image 258
chrisapotek Avatar asked Mar 17 '12 19:03

chrisapotek


People also ask

What is source directory in POM xml?

the src/test/resources directory contains the test resources, the target/classes directory contains the compiled classes. the pom. xml file is the project's Project Object Model, or POM.

Which option rightly gives the project's source directory in Maven?

Source Directories The Maven property ${project. basedir} defaults to the top level directory of the project, so the build directory defaults to the target directory in project base dir. It also sets the property ${project.

How do I add a dependency in Maven?

Add a Java Maven Dependency to the Utility ProjectRight-click the utility project, and select Maven>Add Dependency. Type a dependency name in the Enter groupID… field (e.g., commons-logging) to search for a dependency. Select the dependency, and click OK.

In which folder artifacts build using Maven are created?

The target folder is the maven default output folder. When a project is build or packaged, all the content of the sources, resources and web files will be put inside of it, it will be used for construct the artifacts and for run tests.


2 Answers

You can use the Build Helper Plugin, e.g:

<project>   ...   <build>     <plugins>       <plugin>         <groupId>org.codehaus.mojo</groupId>         <artifactId>build-helper-maven-plugin</artifactId>         <version>3.2.0</version>         <executions>           <execution>             <id>add-source</id>             <phase>generate-sources</phase>             <goals>               <goal>add-source</goal>             </goals>             <configuration>               <sources>                 <source>some directory</source>                 ...               </sources>             </configuration>           </execution>         </executions>       </plugin>     </plugins>   </build> </project> 
like image 95
Péter Török Avatar answered Sep 25 '22 17:09

Péter Török


NOTE: This solution will just move the java source files to the target/classes directory and will not compile the sources.

Update the pom.xml as -

<project>     ....     <build>       <resources>         <resource>           <directory>src/main/config</directory>         </resource>       </resources>      ...     </build> ... </project> 
like image 35
Saikat Avatar answered Sep 25 '22 17:09

Saikat