can't find hamcrest classes when running unit tests

Using IntelliJ 10 CE, trying to import a couple netbeans projects.  None of my JUnit4 tests would compile, so I added the junit.jar file that ships with eclipse as a dependancy. This let me compile my projects with test cases.  But when I try to run them, I get the following exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
 at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
 at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
 at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
 at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
 at com.intellij.junit4.JUnit46ClassesRequestBuilder.getClassesRequest(JUnit46ClassesRequestBuilder.java:34)
 at com.intellij.junit4.JUnit4TestRunnerUtil.buildRequest(JUnit4TestRunnerUtil.java:81)
 at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:64)
 at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:196)
 at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
 at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
 ... 17 more

Why is it looking for the hamcrest stuff? None of my unit tests require it. I extract the junit.jar I am using and it only contains standard unit test stuff.  See the screen shot to see what was in it.
it: Screen shot 2011-02-21 at 1.18.47 AM.png

Doesn't IntelliJ ship with any JUnit jar files? I do have the JUnit plugin instaled and enabled?  Is there somethign more I have to do use JUnit? Should I have even had to manually specify a junit.jar?

Thanks,
~S

4 comments
Comment actions Permalink

Hello shea,

IntelliJ IDEA does ship with a JUnit 4 JAR, and it has a quickfix to add
it as a dependency automatically if some of your JUnit tests require it.
You can try adding the JUnit jar that ships with IntelliJ IDEA (lib\junit-4.8.jar)
as a dependency instead of the one that you took from Eclipse.

Using IntelliJ 10 CE, trying to import a couple netbeans projects.
None of my JUnit4 tests would compile, so I added the junit.jar file
that ships with eclipse as a dependancy. This let me compile my
projects with test cases.  But when I try to run them, I get the
following exception:

Exception in thread "main" java.lang.NoClassDefFoundError:
org/hamcrest/SelfDescribing
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141
)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at
com.intellij.junit4.JUnit46ClassesRequestBuilder.getClassesRequest(JUn
it46ClassesRequestBuilder.java:34)
at
com.intellij.junit4.JUnit4TestRunnerUtil.buildRequest(JUnit4TestRunner
Util.java:81)
at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4Ide
aTestRunner.java:64)
at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JU
nitStarter.java:196)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65
)
Caused by: java.lang.ClassNotFoundException:
org.hamcrest.SelfDescribing
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 17 more
Why is it looking for the hamcrest stuff? None of my unit tests
require it. I extract the junit.jar I am using and it only contains
standard unit test stuff.  See the screen shot to see what was in it.

it:  Image:Screen shot 2011-02-21 at 1.18.47 AM.png

Doesn't IntelliJ ship with any JUnit jar files? I do have the JUnit
plugin instaled and enabled?  Is there somethign more I have to do use
JUnit? Should I have even had to manually specify a junit.jar?

Thanks,
~S
---
Original message URL:
http://devnet.jetbrains.net/message/5287200#5287200


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


1
Comment actions Permalink

Thanks!  I couldn't figure out how to get it to auto add it.  Might be becase I was creating a project from existing sources, but manually adding thejar did the trick.

~S

0
Comment actions Permalink

I added the J-Unit lib as a global library.  But now when I generate an ant build, the ant build fails because it can't find the jUnit libs.

My master ant file contains this:


  <?xml version="1.0" encoding="UTF-8"?>
<project name="intellij" default="all">


  <property file="intellij.properties"/>
  <!-- Uncomment the following property if no tests compilation is needed -->
  <!--
  <property name="skip.tests" value="true"/>
   -->

  <!-- Compiler options -->

  <property name="compiler.debug" value="on"/>
  <property name="compiler.generate.no.warnings" value="off"/>
  <property name="compiler.args" value=""/>
  <property name="compiler.max.memory" value="128m"/>
  <patternset id="ignored.files">
    <exclude name="**/CVS/**"/>
    <exclude name="**/SCCS/**"/>
    <exclude name="**/RCS/**"/>
    <exclude name="**/rcs/**"/>
    <exclude name="**/.DS_Store/**"/>
    <exclude name="**/.svn/**"/>
    <exclude name="**/.pyc/**"/>
    <exclude name="**/.pyo/**"/>
    <exclude name="**/*.pyc/**"/>
    <exclude name="**/*.pyo/**"/>
    <exclude name="**/.git/**"/>
    <exclude name="**/*.hprof/**"/>
    <exclude name="**/_svn/**"/>
    <exclude name="**/.hg/**"/>
    <exclude name="**/*.lib/**"/>
    <exclude name="**/*~/**"/>
    <exclude name="**/*.orig/**"/>
  </patternset>
  <patternset id="library.patterns">
    <include name="*.zip"/>
    <include name="*.war"/>
    <include name="*.egg"/>
    <include name="*.ear"/>
    <include name="*.swc"/>
    <include name="*.jar"/>
  </patternset>
  <patternset id="compiler.resources">
    <include name="**/?*.properties"/>
    <include name="**/?*.xml"/>
    <include name="**/?*.gif"/>
    <include name="**/?*.png"/>
    <include name="**/?*.jpeg"/>
    <include name="**/?*.jpg"/>
    <include name="**/?*.html"/>
    <include name="**/?*.dtd"/>
    <include name="**/?*.tld"/>
    <include name="**/?*.ftl"/>
  </patternset>

  <!-- JDK definitions -->

  <property name="jdk.bin.1.6" value="${jdk.home.1.6}/bin"/>
  <path id="jdk.classpath.1.6">
    <fileset dir="${jdk.home.1.6}">
      <include name="../../../../Support/Deploy.bundle/Contents/Resources/Java/deploy.jar"/>
      <include name="lib/dt.jar"/>
      <include name="lib/javaws.jar"/>
      <include name="lib/jce.jar"/>
      <include name="lib/jconsole.jar"/>
      <include name="lib/management-agent.jar"/>
      <include name="lib/plugin.jar"/>
      <include name="lib/sa-jdi.jar"/>
      <include name="../Classes/alt-rt.jar"/>
      <include name="../Classes/charsets.jar"/>
      <include name="../Classes/classes.jar"/>
      <include name="../Classes/jsse.jar"/>
      <include name="../Classes/ui.jar"/>
      <include name="lib/ext/apple_provider.jar"/>
      <include name="lib/ext/dnsns.jar"/>
      <include name="lib/ext/localedata.jar"/>
      <include name="lib/ext/sunjce_provider.jar"/>
      <include name="lib/ext/sunpkcs11.jar"/>
    </fileset>
  </path>

  <property name="project.jdk.home" value="${jdk.home.1.6}"/>
  <property name="project.jdk.bin" value="${jdk.bin.1.6}"/>
  <property name="project.jdk.classpath" value="jdk.classpath.1.6"/>


  <!-- Project Libraries -->

  <path id="library.commonslogging.classpath">
    <fileset dir="${basedir}/../external_jars/commons-logging-1.1.1">
      <patternset refid="library.patterns"/>
    </fileset>
  </path>

  <path id="library.flyingsaucerxhtml.classpath">
    <fileset dir="${basedir}/../external_jars/flyingsaucer-R8">
      <patternset refid="library.patterns"/>
    </fileset>
  </path>


  <!-- Global Libraries -->

  <path id="library.junit-4.8.classpath">
    <pathelement location="${idea.home}/lib/junit-4.8.jar"/>
  </path>

  <!-- Modules -->

  <import file="${basedir}/../altkey_printing_support/module_altkey_printing_support.xml"/>

  <import file="${basedir}/../altkey_xml/module_altkey_xml.xml"/>

  <import file="${basedir}/../altkey_comms/module_altkey_comms.xml"/>

  <import file="${basedir}/../altkey_printing/module_altkey_printing.xml"/>

  <import file="${basedir}/../altkey_util/module_altkey_util.xml"/>

  <import file="${basedir}/../handprint_beans/module_handprint_beans.xml"/>

  <import file="${basedir}/../handprint_pc/module_handprint_pc.xml"/>

  <target name="init" description="Build initialization">
    <!-- Perform any build initialization in this target -->
  </target>

  <target name="clean" depends="clean.module.altkey_printing_support, clean.module.altkey_xml, clean.module.altkey_comms, clean.module.altkey_printing, clean.module.altkey_util, clean.module.handprint_beans, clean.module.handprint_pc" description="cleanup all"/>

  <target name="build.modules" depends="init, clean, compile.module.altkey_printing_support, compile.module.altkey_xml, compile.module.altkey_comms, compile.module.altkey_printing, compile.module.altkey_util, compile.module.handprint_beans, compile.module.handprint_pc" description="build all modules"/>

  <target name="all" depends="build.modules" description="build all"/>
</project>



And my modules's ant file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project name="module_altkey_xml" default="compile.module.altkey_xml">
  <dirname property="module.altkey_xml.basedir" file="${ant.file.module_altkey_xml}"/>

  <property name="module.jdk.home.altkey_xml" value="${project.jdk.home}"/>
  <property name="module.jdk.bin.altkey_xml" value="${project.jdk.bin}"/>
  <property name="module.jdk.classpath.altkey_xml" value="${project.jdk.classpath}"/>

  <property name="compiler.args.altkey_xml" value="${compiler.args}"/>

  <property name="altkey_xml.output.dir" value="${module.altkey_xml.basedir}/../intellij/out/production/altkey_xml"/>
  <property name="altkey_xml.testoutput.dir" value="${module.altkey_xml.basedir}/../intellij/out/test/altkey_xml"/>

  <path id="altkey_xml.module.bootclasspath">
    <!-- Paths to be included in compilation bootclasspath -->
  </path>

  <path id="altkey_xml.module.production.classpath">
    <path refid="${module.jdk.classpath.altkey_xml}"/>
    <path refid="library.junit-4.8.classpath"/>
  </path>

  <path id="altkey_xml.runtime.production.module.classpath">
    <pathelement location="${altkey_xml.output.dir}"/>
    <path refid="library.junit-4.8.classpath"/>
  </path>

  <path id="altkey_xml.module.classpath">
    <path refid="${module.jdk.classpath.altkey_xml}"/>
    <pathelement location="${altkey_xml.output.dir}"/>
    <path refid="library.junit-4.8.classpath"/>
  </path>

  <path id="altkey_xml.runtime.module.classpath">
    <pathelement location="${altkey_xml.testoutput.dir}"/>
    <pathelement location="${altkey_xml.output.dir}"/>
    <path refid="library.junit-4.8.classpath"/>
  </path>


  <patternset id="excluded.from.module.altkey_xml">
    <patternset refid="ignored.files"/>
  </patternset>

  <patternset id="excluded.from.compilation.altkey_xml">
    <patternset refid="excluded.from.module.altkey_xml"/>
  </patternset>

  <path id="altkey_xml.module.sourcepath">
    <dirset dir="${module.altkey_xml.basedir}">
      <include name="src"/>
    </dirset>
  </path>


  <target name="compile.module.altkey_xml" depends="compile.module.altkey_xml.production,compile.module.altkey_xml.tests" description="Compile module altkey_xml"/>

  <target name="compile.module.altkey_xml.production" description="Compile module altkey_xml; production classes">
    <mkdir dir="${altkey_xml.output.dir}"/>
    <javac destdir="${altkey_xml.output.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true" executable="${module.jdk.bin.altkey_xml}/javac">
      <compilerarg line="${compiler.args.altkey_xml}"/>
      <bootclasspath refid="altkey_xml.module.bootclasspath"/>
      <classpath refid="altkey_xml.module.production.classpath"/>
      <src refid="altkey_xml.module.sourcepath"/>
      <patternset refid="excluded.from.compilation.altkey_xml"/>
    </javac>

    <copy todir="${altkey_xml.output.dir}">
      <fileset dir="${module.altkey_xml.basedir}/src">
        <patternset refid="compiler.resources"/>
        <type type="file"/>
      </fileset>
    </copy>
  </target>

  <target name="compile.module.altkey_xml.tests" depends="compile.module.altkey_xml.production" description="compile module altkey_xml; test classes" unless="skip.tests"/>

  <target name="clean.module.altkey_xml" description="cleanup module">
    <delete dir="${altkey_xml.output.dir}"/>
    <delete dir="${altkey_xml.testoutput.dir}"/>
  </target>
</project>



~S
0
Comment actions Permalink

If I check the 'include idea.home' property when I generate my ant files, everything works now.  Thanks.

~S

0

Please sign in to leave a comment.