I am trying to integrate pmd into my project. But I am getting following error
java.lang.IllegalArgumentException: No rules found. Maybe you mispelled a rule name?
The pom.xml entry is as follows -
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.7</version>
<configuration>
<linkXRef>false</linkXRef>
<rulesets>
<ruleset>
pmdruleset.xml
</ruleset>
</rulesets>
</configuration>
</plugin>
</plugins>
</reporting>
The custom rule set file contains following -
<?xml version="1.0"?>
<ruleset name="Controversial"
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">
<description>
<rule ref="rulesets/java/errorprone.xml/NullAssignment"/>
</description>
</ruleset>
I am unable to understand what is wrong. Can someone help!
#eclipse-pmd is right, the rule tag needs to be a child of the ruleset tag.
Additionally, the rule you are trying to use (NullAssignment), is not in the ruleset errorprone, but in controversial. With PMD 6, the rules have additionally been organized into categories and is now in category "errorprone". More on this will follow.
maven-pmd-plugin 3.7 / PMD 5.5.1
You are using maven-pmd-plugin version 3.7 -> this means, you automatically use an old PMD version (version 5.5.1 to be precise). For this version, your ruleset should look like the following:
<?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">
<description>
Custom Ruleset
</description>
<rule ref="rulesets/java/controversial.xml/NullAssignment"/>
</ruleset>
Documentation for PMD 5.5.1 is available at: https://pmd.github.io/pmd-5.5.1/pmd-java/rules/java/controversial.html#NullAssignment
maven-pmd-plugin 3.9.0 / PMD 6.0.1
If you switch to the latest maven-pmd-plugin version 3.9.0, you'll automatically use PMD 6.0.1 and benefit from the latest bugfixes. You can continue to use the ruleset from above, however you'll see a deprecation notice, since we moved the rule. To get rid of this warning, use the following rule reference:
<rule ref="category/java/errorprone.xml/NullAssignment" />
Documentation for PMD 6.0.1 is available at: https://pmd.github.io/pmd-6.0.1/pmd_rules_java_errorprone.html#nullassignment
Documentation about rulesets is here: https://pmd.github.io/pmd-6.0.1/pmd_userdocs_understanding_rulesets.html
After stumbling my way through setting up a BlazeDS service, I was finally able to get the list of services through the Flex Builder Data/Services Wizzard. However when testing any of the services, I get the Error popup of
> "InvocationTargetException:There was an error while invoking the
> operation. Check your operation inputs or server code and try invoking
> the operation again.
>
> Reason: java.io.FileNotFoundException:
> http://127.0.0.1:8080/portlets-0.0.1-SNAPSHOT/messagebroker/amf/
I could not find anyone else with a similar issue, and am unfamiliar with services setup. Below are my configurations. Any help would be greatly appreciated.
I can post config files if it will help, i was getting improper code format errors trying to insert them in this single post.
This service I am testing does not reach the function in the server, it is throwing this error before getting that far...
I have also noticed that I cannot run the flex application through a web browser using the standard run configuration in eclipse as it tries to target:
[http://127.0.0.1:8080/portlets-0.0.1-SNAPSHOT/messagebroker/amf/FlexMissionsOverview/MissionsPortlet.html][1]
Which throws a 404 error on tomcat since the file does not exist there. Are these possibly connected?
Any help would be greatly appreciated.
Added Details based on feedback:
Yes, the project name is "FlexMissionsOverview" with a Base Flex Application Called "MissionsPortlet"(.mxml).
The webapp is deployed to "webapps/portlets-0.0.1-SNAPSHOT/"
Compiler settings below:
-services "C:\liferay\liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\webapps\portlets-0.0.1-SNAPSHOT\WEB-INF\flex\services-config.xml" -locale en_US
-show-deprecation-warnings=false
-show-binding-warnings=false
Note: I am setting my project back up to where I had gotten to by the time of this post, if anything changes I will make another edit.
services-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<services-config>
<services>
<service-include file-path="remoting-config.xml" />
<service-include file-path="proxy-config.xml" />
<service-include file-path="messaging-config.xml" />
</services>
<factories>
<factory id="spring" class="flex.samples.factories.SpringFactory"/>
</factories>
<services>
<service id="remoting-service" class="flex.messaging.services.RemotingService">
<adapters>
<adapter-definition id="java-object"
class="flex.messaging.services.remoting.adapters.JavaAdapter"
default="true" />
</adapters>
<default-channels>
<channel ref="my-amf" />
</default-channels>
</service>
</services>
<channels>
<channel-definition id="my-amf"
class="mx.messaging.channels.AMFChannel">
<endpoint
url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf"
class="flex.messaging.endpoints.AMFEndpoint" />
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
<polling-enabled>false</polling-enabled>
</properties>
</channel-definition>
</channels>
<logging>
<!-- You may also use flex.messaging.log.ServletLogTarget -->
<target class="flex.messaging.log.ConsoleTarget" level="Error">
<properties>
<prefix>[BlazeDS] </prefix>
<includeDate>false</includeDate>
<includeTime>false</includeTime>
<includeLevel>true</includeLevel>
<includeCategory>false</includeCategory>
</properties>
<filters>
<pattern>Endpoint.</pattern>
<pattern>Service.</pattern>
<pattern>Configuration</pattern>
</filters>
</target>
</logging>
</services-config>
Pointing to the file directly on the tomcat server seems to work fine for testing the Flex Application via Eclipse, but I am still getting the same "FileNotFoundException" When trying to test the BlazeDS Services in the Data/Services Wizard in FlashBuilder.
Is there any indication of what the FileNotFoundException is coming from when trying to test the services? It may be some of the config information, but I am not positive, since I am used to these Exceptions saying what file it could not find.
The only class that I have in my project that is referenced above is the two listener classes, the other classes I believe come from my maven dependencies.
I am attempting to get my JUnit tests for an Android application running using Ant.
While using Eclipse, it is no problem, all is compiled and can be run with no problem.
At the moment I am receiving a ClassNotFoundException to org.junit.Test.
I am running the following commands
ant clean debug - success
ant uninstall - success
ant installt - success
ant test - failure
error log:
test:
[echo] Running tests ...
[exec] INSTRUMENTATION_RESULT: shortMsg=java.lang.ClassNotFoundException
[exec] INSTRUMENTATION_RESULT: longMsg=java.lang.ClassNotFoundException: org.junit.Test
[exec] INSTRUMENTATION_CODE: 0
I suppose, it misses junit.jar file. I added it into my ANT_HOME/lib directory, but it didn't have any effect. ant-junit.jar library was already in "ANT_HOME/lib", I didn't need to copy it over.
I also tried to add it in the classpath of my test project and marked it to be exported. Also in that case the result remains unchanged.
I also let eclipse to generate a build.xml to be and merged it with the file generated by android update project. It didn't make any difference, I receive the same error.
I am sure that I am missing something very easy here. If further configuration details are needed, I'll be glad to provide them. I appreciate your help.
build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="FSTest" default="help">
<property file="local.properties" />
<property file="ant.properties" />
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<loadproperties srcFile="project.properties" />
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<import file="custom_rules.xml" optional="true" />
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>
ant.properties:
tested.project.dir=../FS
external.libs.dir=libs
project.properties:
target=android-11
The problem was in my build.xml file. I modified it according to the example given here: http://www.vogella.com/articles/ApacheAnt/article.html and thereafter it worked.
These lines were the ones that maked the difference:
<path id="junit.class.path">
<pathelement location="libs/junit.jar" />
<pathelement location="${build.dir}" />
</path>
The JUnit task page lists several ways in which you can make the JUnit jar available to Ant:
http://ant.apache.org/manual/Tasks/junit.html
In particular, option 1 would require adding both "junit.jar" and "ant-junit.jar" to "ANT_HOME/lib". Any of the 5 options listed there should work just fine though.
While running junit test in eclipse I am getting this Exception:
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
I've added junit.jar library file.
I've tried different versions of junit.jar: 4.4, 4.8, etc.
How do I fix this Exception?
Add hamcrest-all-X.X.jar to your classpath.
Latest version as of Feb 2015 is 1.3:
http://code.google.com/p/hamcrest/downloads/detail?name=hamcrest-all-1.3.jar&can=2&q=
According to the JUnit GitHub team website (https://github.com/junit-team/junit/wiki/Download-and-Install), junit.jar and hamcrest-core.jar are both needed in the classpath when using JUnit 4.11.
Here is the Maven dependency block for including junit and hamcrest.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.1.2</version>
<scope>test</scope>
</dependency>
<!-- Needed by junit -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
A few steps you have to follow:
Right click on the project.
Choose Build Path Then from its menu choose Add Libraries.
Choose JUnit then click Next.
Choose JUnit4 then Finish.
Works for me: IntelliJ IDEA 13.1.1, JUnit4, Java 6
I changed the file in project path: [PROJECT_NAME].iml
Replaced:
<library>
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
By:
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
So the final .iml file is:
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
P.S.: save the file and don't let to IntelliJ Idea reload it. Just once.
You need junit-dep.jar because the junit.jar has a copy of old Hamcrest classes.
Just in case there's anyone here using netbeans and has the same problem, all you have to do is
Right click on TestLibraries
Click on Add Library
Select JUnit and click add library
Repeat the process but this time click on Hamcrest and the click add library
This should solve the problem
This problem is because of your classpath miss hamcrest-core-1.3.jar. To resolve this add hamcrest-core-1.3.jar as you add junit-4.XX.jar into your classpath.
At first, I encounter this problem too, but after I refer to the official site and add hamcrest-core-1.3.jar into classpath with command line, it works properly finally.
javac -d ../../../../bin/ -cp ~/libs/junit-4.12.jar:/home/limxtop/projects/algorithms/bin MaxHeapTest.java
java -cp ../../../../bin/:/home/limxtop/libs/junit-4.12.jar:/home/limxtop/libs/hamcrest-core-1.3.jar org.junit.runner.JUnitCore com.limxtop.heap.MaxHeapTest
You need to add the hamcrest-core JAR to the classpath as described here: https://github.com/junit-team/junit4/wiki/Download-and-Install
As a general rule, always make sure hamcrest is before any other testing libraries on the classpath, as many such libraries include hamcrest classes and may therefore conflict with the hamcrest version you're using. This will resolve most problems of the type you're describing.
the simplest way of solving the problem to begin with is copying latest version of hamcrest-code.jar into your CLASSPATH that is the file you store other .jar files needed for compilation and running of your application.
that could be e.g.: C:/ant/lib
It sounds like a classpath issue, so there are a few different ways to go about it. Where does org/hamcret/SelfDescribing come from? Is that your class or in a different jar?
Try going to your project Build Path and on the Libraries tab, add a Library. You should be able to choose JUnit to your project. This is a little bit different than just having the JUnit jar file In your project.
In your Run Configuration for the JUnit test, check the Classpath. You could probably fix this by adding making sure your Classpath can see that SelfDescribing class there. The Run option in Eclipse has a different set of options for the JUnit options.
If this problem arise in a RCP project it can be because JUnit has been explicitly imported.
Check the editor for your plugin.xml under Dependencies tab, remove the org.junit from the Imported Packages and add org.junit to the Required Plug-ins.
The problem is when you set up eclipse to point to JRE instead of JDK. JRE has junit4.jar in the lib/ext folder, but not hamcrest.jar :) So the solution is to check installed JREs in Eclipse, remove the existing one and create a new one pointing to your JDK.
This happens when you run Ant via command line. The implicit user dependencies are added in the classpath at the end and take precedence over the project-added classpath. Run Ant with -nouserlib flag. The implicit dependencies would be excluded from the classpath.
There is a better answer to solve this problem.
add dependency
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
The hamcrest-core-1.3.jar available on maven repository is deprecated.
Download working hamcrest-core-1.3.jar from official Junit4 github link .
If you want to download from maven repository, use latest hamcrest-XX.jar.
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
I had the same problem, the solution is to add in build path/plugin the jar org.hamcrest.core_1xx, you can find it in eclipse/plugins.
A few steps you have to follow:
Right click on the project.
Choose Build Path & then from its menu choose Add Libraries.
Choose JUnit then click Next.
Choose JUnit4 then Finish.
This works for me...
"java.lang.SecurityException: class" org.hamcrest.Matchers "'s signer information does not match signer information of other classes in the same package"
Do it:
Right-click on your package
click on Build Path -> Configure Build Path
Click on the Libraries tab
Remove JUnit
Apply and close
Ready.
Try adding the jar files manually or try with force update with the latest hamcrest.jar
This worked in Ant 1.7.1 but no longer works in Ant 1.8.1. Is this a bug or is there a new and/or better way to achieve what I'm trying to do?
The Project consists of 2 components, each component has it's own build file and properties file, there is also a top level build file and properties file for common ant targets and properties. It is laid out like so:
/project/
component-a/
build.properties
build.xml
component-b/
build.properties
build.xml
build.properties
build.xml
/project/build.properties:
common.root.dir=/project
/project/build.xml:
<project name="common">
<dirname file="${ant.file.common}" property="common.base.dir"/>
<loadproperties srcfile="${common.base.dir}/build.properties"/>
</project>
/project/component-b/build.properties:
dist.dir=${common.root.dir}/component-b/dist
/project/component-b/build.xml:
<project name="component-b">
<dirname property="component.b.base.dir" file="${ant.file.component-b}"/>
<import file="${component.b.base.dir}/../build.xml"/>
<loadproperties srcfile="${component.b.base.dir}/build.properties"/>
</project>
/project/component-a/build.properties:
dist.dir=${common.root.dir}/component-a/dist
/project/component-a/build.xml:
<project name="component-a">
<dirname property="component.a.base.dir" file="${ant.file.component-a}"/>
<property name="project.root.dir" location="${component.a.base.dir}/.."/>
<import file="${project.root.dir}/build.xml"/>
<loadproperties srcfile="${component.a.base.dir}/build.properties"/>
<loadproperties srcfile="${project.root.dir}/component-b/build.properties" prefix="component.b"/>
<target name="print.unresolved.property">
<echo>${component.b.dist.dir}</echo>
</target>
</project>
To see the error run: ant -f /project/component-a/build.xml print.unresolved.property
If using Ant 1.8.1 the output will be:
print.unresolved.property:
[echo] ${common.root.dir}/component-b/dist
Why is common.root.dir not resolving to /project?
For others encountering this problem, I've uncovered that it is indeed a bug; while I haven't found the relevant bug report, I built ant using the latest source code from their repository and the property now resolves correctly. Here's to hoping that v1.8.2 is released sooner rather than later.