how to override maven-war-plugin source directory - java

I had old web application project. Then I added pom.xml, and add maven-war-plugin. In the old project sources were in "Java Resources/src"directory.
In my maven-war plugin I trying overriding default source directorie like this, but not working.
during compilation i see:
`
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # webproj ---
[INFO] No sources to compile
[INFO]
`
my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<webXml>WebContent\WEB-INF\web.xml</webXml>
<webappDirectory>WebContent</webappDirectory>
<source>${project.basedir}\src</source>
<target>${maven.compiler.target}</target>
<encoding>utf-8</encoding>
</configuration>
</plugin>

If you are planning to migrate to Maven, I suggest that you follow the Maven Standard Directory Layout. Consequently, you should move your source files to src/main/java, static resources like .properties files to the src/main/resources, and webapp resources like CSS and JavaScript files to src/main/webapp.

The Maven-war-plugin use the project source folder, to override the location you must put in your pom like this:
<build>
<sourceDirectory>/Java Resources/src</sourceDirectory>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${version.build-helper-maven-plugin}</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>social/src/main/java</source>
</sources>
</configuration>
</execution>
</executions>
...
</plugins>
<build>

You can specify warSourceDirectory in maven-war-plugin configuration:
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>old/project/source</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
...
</project>

Related

jqassistant Report generation fails with Maven site

I've set up jqassistant successfully, created some rules which are checked in our maven build.
However, when I try to create a Report from the results of the checks I'm getting the following infofrom the console when running mvn site and of course no report is generated:
[INFO] --- maven-site-plugin:3.3:site (default-site) # mvb-bfa ---
[INFO] configuring report plugin org.apache.maven.plugins:maven-project- info-reports-plugin:2.8.1
[INFO] configuring report plugin com.buschmais.jqassistant.scm:jqassistant-maven-plugin:1.1.2
[WARNING] ignoring com.buschmais.jqassistant.scm:jqassistant-maven-plugin:1.1.2:report goal since it is not a report: should be removed from reporting configuration in POM
Relevant part of pom.xml:
<reporting>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant.scm</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
Scanning and analyzing is working without problems.
Any Ideas?
Edit: Configuration for scan/analyze
<build>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant.scm</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>1.1.2</version>
<extensions>true</extensions>
<executions>
<execution>
<id>default</id>
<goals>
<goal>scan</goal>
<goal>analyze</goal>
</goals>
<configuration>
<failOnViolations>false</failOnViolations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The problem in your configuration is that you have <extensions>true</extensions> in your configuration.
From the documentation, the basic correct configuration for the plugin is the following and note that:
The jQAssistant Maven plugin must be configured in the pom.xml of the root module, it should not be overwritten by sub-modules.
This means this configuration needs to be at the top-level POM in a multi-module project.
<project>
...
<build>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant.scm</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>1.1.2</version>
<executions>
<execution>
<id>scan</id>
<goals>
<goal>scan</goal>
</goals>
</execution>
<execution>
<id>analyze</id>
<goals>
<goal>analyze</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.buschmais.jqassistant.scm</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>1.1.2</version>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
...
</project>
It appears that the current documentation has both versions (with and without <extensions>true</extensions>) because it might be needed in build environments where other extensions are present. An issue was created to track this: https://github.com/buschmais/jqassistant/issues/349

Multiple Source Folders for Eclipse Java Project & Maven

Question/Problem:
How to add an additional source folder to a standard java console Maven project using Eclipse (Luna) so that Maven sees the path for jar build.
The expected result is to somehow configure pom.xml so that Maven plugins in Eclipse can be executed cleanly.
Assumptions - a successful add of an additional source folder via project (right click) -> new -> source folder.
To let Maven know about the new source folder for building a jar I had to add the following to my pom.xml:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<includes>
<include>[your source folder goes here]/**/*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>[your source folder goes here]</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Be sure to add the pluginManagement tags around plugins as omitting this tag prevented the mojo plugin to recognize the executions tag.
Perhaps more later on the success of the actual jar construction...
Add generated sources into configuration of maven-compiler-plugin:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<generatedSourcesDirectory>[additional directory]</generatedSourcesDirectory>
</configuration>
</plugin>
or provide additional execution:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>compile-additional-sources</id>
<goals><goal>compile</goal></goals>
<configuration>
<source>[additional sources]</source>
</configuration>
</execution>
</executions>
</plugin>

Download source jars using Maven2 and pom

I am using Maven2 to build my project. I want my build to automatically download dependency source jars when it is compiled. Dependency executable jars are downloading correctly. My dependency looks like this:
...
<dependencies>
<dependency>
<groupId>id.name</groupId>
<artifactId>artifact-name</artifactId>
<version>1403.00</version>
</dependency>
</dependencies>
...
I do have the maven source plugin:
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
...
I've also tried adding this configuration to the pom under the maven-source-plugin:
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
What do I need to add to my pom file to make this happen?
Add this to your POM:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>download-sources</id>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>

Maven 3 cobertura 2.5.1 configuration

I have configured cobertura in a maven 3 project. My requirement is to configure cobertura in parent pom and configure the ignore, exclude values in child poms in multiple projects. The basic configuration of cobutura plugin in pom xml with reference to it in child pom worked fine. But when i tried to configure ignore, exclude packages in child pom and added instrument goal in parent pom, i'm getting directory issues with the plugin. Google search gave me this link, but not successful so far. : http://blog.bielu.com/2012/01/errata-to-maven2-maven3-migration.html
Here is my configuration:
Parent pom:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<check>
<haltOnFailure>true</haltOnFailure>
<branchRate>50</branchRate>
<lineRate>50</lineRate>
<haltOnFailure>true</haltOnFailure>
<totalBranchRate>50</totalBranchRate>
<totalLineRate>50</totalLineRate>
<packageLineRate>50</packageLineRate>
<packageBranchRate>50</packageBranchRate>
</check>
</configuration>
<executions>
<execution>
<id>instrument-code</id>
<phase>process-classes</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
Child pom:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<instrumentation>
<ignores>
<ignore>to.ignore.*</ignore>
</ignores>
<excludes>
<exclude>to/exclude/*</exclude>
</excludes>
</instrumentation>
</configuration>
</plugin>
</plugins>
</build>
Error thrown:
[ERROR] Failed to execute goal org.codehaus.mojo:cobertura-maven-plugin:2.5.1:instrument (instrument-code) on project test: Unable to prepare instrumentation directory. source and destination are the same directory.
Tried several configuration, but no luck yet. Please advice me on this.
Thanks.

Should the wsdlDirectory setting in maven have an effect?

Is the wsdlDirectory setting in maven supposed to have an effect? I am finding that the setting:
<wsdlDirectory>${basedir}/src/main/resources/wsdl/</wsdlDirectory>
has no effect.
Executing the command below
mvn -X clean:clean jaxws:wsimport
always results in the output below, unless the wsdl files are moved to /home/projects/amazon/fps/trunk/src/wsdl
[DEBUG] The wsdl Directory is /home/projects/amazon/fps/trunk/src/wsdl
[DEBUG] The binding Directory is
/home/projects/amazon/fps/trunk/src/jaxws
[DEBUG] The wsdl Directory
is /home/projects/amazon/fps/trunk/src/wsdl
[INFO] Nothing to do, no
WSDL found!
I am using 2.2.1 on my Debian build machine and Embedded maven 3.0.2 on my Windows 7 Eclipse environment.
My pom.xml is as follows (irrelevant bits removed):
<project xmlns="..." xmlns:xsi="..." xsi:schemaLocation="...">
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>AmazonFPSImport</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>
${basedir}/src/main/resources/wsdl/
</wsdlDirectory>
<wsdlFiles>
<wsdlFile>AmazonFPS.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>/wsdl/AmazonFPS.wsdl</wsdlLocation>
<sourceDestDir>
${basedir}/target/generated-sources/amazon/
</sourceDestDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Try moving the configuration section outside the <execution> tags. Or, bind to a specific phase
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>

Categories

Resources