I have a maven project which I compile with Netbeans. I there a way to specify a different build directory where the compiled binary code is copied after compilation?
Asked
Active
Viewed 6.1k times
28
-
2best answer I found: http://stackoverflow.com/a/12598554/520567 – akostadinov Jul 12 '13 at 14:42
-
Agreed, using POM profiles is definitely the most flexible and powerful solution IMO. – Dawngerpony Apr 30 '15 at 09:44
2 Answers
24
Sure. Update your POM with:
<build>
<directory>my_new_build_path</directory>
</build>
Part 2: To specify the output path for a WAR:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<warName>test-web-app</warName>
<outputDirectory>my_output_path</outputDirectory>
</configuration>
</plugin>

Reimeus
- 158,255
- 15
- 216
- 276
-
Is this going to work for every sub maven project if I place it only on my parent POM file? – user1285928 Jul 20 '12 at 22:09
-
Good point. Having this setting means that the build directory for every module is the same, instead of one directory per module. – Reimeus Jul 20 '12 at 22:15
-
I forgot to write that I have bundles without `maven-war-plugin`. I also have `maven-compiler-plugin`. How I can configure it to change the output directory? – user1285928 Jul 20 '12 at 22:40
-
You can modify the outputDirectory build setting. If you just want to change the output path of the JAR file, then you can use maven-jar-plugin. – Reimeus Jul 20 '12 at 23:01
-
just out of curiosity, why not reconfigure netbeans to use the standard maven structure. With eclipse, i execute the following on the command line for a web project with a pom.xml. It generates all the necessary eclipse project files for me: mvn -Dwtpversion=2.0 eclipse:eclipse I'd be surprised if there isn't a similar plugin for netbeans. – Matt Jul 21 '12 at 00:57
19
<project>
<build>
<outputDirectory>target/classes</outputDirectory>
</build>
</project>

Michał Kalinowski
- 16,925
- 5
- 35
- 48
-
2I tested it - the compiled files are moved there. I want to specify the build directory for the final WAR package. – user1285928 Jul 20 '12 at 22:03
-
OK, all you need is [here](http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html). I don't feel what exactly you need to set (I though it's compiled stuff directory) so choose what you need. – Michał Kalinowski Jul 23 '12 at 06:47