• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Maven PMD Error with ruleset

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a Maven WebApp project (Just a HelloWorld Servlet) in Eclipse and running tomcat server. My ultimate aim is to fail the build if the code contains out.print statements. I have defined the maven pmd plugin 2.5 in the pom.xml as below and defined a customized ruleset in a file called sop.xml as below.

But when I right click the project -> Run As -> Maven Build and try to package,it is throwing an error as follows,

"Failed to execute goal org.apache.maven.plugins:maven-pmd-plugin:2.5:pmd (pmd) on project MavenWebArtifactId: An error has occurred in PMD Report report generation. Could not find resource 'c:\rulesets\sop.xml'".

I am new to Maven and requesting all your kind help on this regard. Thanks.


sop.xml
-----------

<?xml version="1.0"?>
<ruleset name="Custom ruleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>This ruleset checks my code for println statements</description>
<rule ref="rulesets/JavaLogging.xml" message="Must handle exceptions"> </rule>
</ruleset>


POM.xml
-----------

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MavenWebGroupId</groupId>
<artifactId>MavenWebArtifactId</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>MavenWebName</name>
<description>MavenWebDescription</description>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
<configuration>
<skip>false</skip>
<targetJdk>${compile.source}</targetJdk>
<rulesets>
<ruleset>c:\rulesets\sop.xml</ruleset>
</rulesets>
<linkXref>true</linkXref>
<failOnViolation>true</failOnViolation>
</configuration>
<executions>
<execution>
<id>run-pmd</id>
<phase>prepare-package</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
</dependencies>
</project>

 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chances are that your ruleset path is invalid and it's reading "C:\rulesets\sop.xml" as being relative to the project, not relative to the root of the C drive (helpful hint: in Java, usually using Unix-style paths works better).

Maven doesn't like to pull resources from locations outside of the project directory tree (not counting the download/cache mechanism). That's because in theory every Maven project can be collapsed with a "mvn clean" command, zipped, sent to (or from!) Ulan Bator, installed on another machine and completely rebuilt with a single Maven command. You can't do that if there are things that are dependent on the original machine's filesystem layout.
 
I'm gonna teach you a lesson! Start by looking at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic