I am trying to apply maven to an existing project which already has a directory structure in place. All I can find from previous question is the following.
Maven directory structure
However, my requirement is more detailed. Please see below for the directory structure:
<root dir>
|
+--src-java
|
+--src-properties
|
+--WEB-INF
I know we could have something like
<build>
<sourceDirectory>src-java</sourceDirectory>
...
</build>
But sourceDirectory
is for JAVA source code only, if I'm not mistaken.
For the above structure, how do I declare it in pom.xml
? Moving the directory is my last option right now.
maven-project/src/main – contains source code and resources that become part of the artifact. maven-project/src/test – holds all the test code and resources. maven-project/src/it – usually reserved for integration tests used by the Maven Failsafe Plugin.
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.
I guess you need to have something similar to below.
Seeing WEB-INF
, I assume you want to build a war. Maven war plugin does this. You will need to configure this a bit since the folder structure is non-standard - for instance you may need to specify the location of web.xml using webXml
property. These are documented in the usage page.
<build>
<sourceDirectory>src-java</sourceDirectory>
...
<resources>
<resource>
<directory>src-properties</directory>
</resource>
</resources>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory>WEB-INF</warSourceDirectory>
...
</configuration>
</plugin>
</plugins>
</build>
You can change the default directory structure declared in the Super POM by overwriting them in your pom.
For your example, e.g.
<sourceDirectory>src-java</sourceDirectory>
<resources>
<resource>
<directory>src-properties</directory>
</resource>
</resources>
Maven will copy all resources to the jar file. If you want to include WEB-INF to the jar it would be best to move it into the specified resource directory. Otherwise you have to copy it by your own (with maven plugins) to the target directory - I suppose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With