Results 1 to 2 of 2
  1. #1
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default How to add the hamcrest library?

    Hi,

    I tried out IntelliJ now and the first steps was quite nice: I was able to import my project (ok, the project files wasn't added to source control. I had to do that on my own ...) but when I want to run the unit tests, I get the error, that hamcrest is not found:
    Java Code:
    /home/konrad/bin/jdk/bin/java -ea -Didea.launcher.port=7533 -Didea.launcher.bin.path=/home/konrad/bin/java/idea-IU-135.690/bin -Dfile.encoding=UTF-8 -classpath /home/konrad/bin/java/idea-IU-135.690/lib/idea_rt.jar:/home/konrad/bin/java/idea-IU-135.690/plugins/junit/lib/junit-rt.jar:/home/konrad/Projects/jAdventure/bin:/home/konrad/bin/jdk/jre/lib/javaws.jar:/home/konrad/bin/jdk/jre/lib/rt.jar:/home/konrad/bin/jdk/jre/lib/management-agent.jar:/home/konrad/bin/jdk/jre/lib/deploy.jar:/home/konrad/bin/jdk/jre/lib/charsets.jar:/home/konrad/bin/jdk/jre/lib/plugin.jar:/home/konrad/bin/jdk/jre/lib/jsse.jar:/home/konrad/bin/jdk/jre/lib/jfxswt.jar:/home/konrad/bin/jdk/jre/lib/resources.jar:/home/konrad/bin/jdk/jre/lib/jce.jar:/home/konrad/bin/jdk/jre/lib/jfr.jar:/home/konrad/bin/jdk/jre/lib/ext/localedata.jar:/home/konrad/bin/jdk/jre/lib/ext/sunec.jar:/home/konrad/bin/jdk/jre/lib/ext/jfxrt.jar:/home/konrad/bin/jdk/jre/lib/ext/sunjce_provider.jar:/home/konrad/bin/jdk/jre/lib/ext/dnsns.jar:/home/konrad/bin/jdk/jre/lib/ext/cldrdata.jar:/home/konrad/bin/jdk/jre/lib/ext/nashorn.jar:/home/konrad/bin/jdk/jre/lib/ext/zipfs.jar:/home/konrad/bin/jdk/jre/lib/ext/sunpkcs11.jar:/home/konrad/Projects/jAdventure/lib/hsqldb.jar:/home/konrad/Projects/jAdventure/lib/jdom.jar:/home/konrad/bin/java/idea-IU-135.690/lib/junit-4.11.jar:/home/konrad/Projects/jAdventure/lib/de.kneitzel.lib-0.0.1.jar:/home/konrad/Projects/jAdventure/lib/junit-4.11.jar com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 @/tmp/idea_junit4562325699977740332.tmp @w@/tmp/idea_working_dirs_junit4394378282833855253.tmp -socket58246
    Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
    	at java.lang.ClassLoader.defineClass1(Native Method)
    	at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    	at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
    	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    	at com.intellij.junit4.JUnit46ClassesRequestBuilder.getClassesRequest(JUnit46ClassesRequestBuilder.java:40)
    	at com.intellij.junit4.JUnit4TestRunnerUtil.buildRequest(JUnit4TestRunnerUtil.java:88)
    	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:39)
    	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
    	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:483)
    	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
    Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    	... 22 more
    
    Process finished with exit code 1
    And now I am wondering how I should add the library. IntelliJ already contains it. So inside idea-IU-135.690/lib I find
    hamcrest-core-1.3.jar
    hamcrest-library-1.3.jar

    So what setting is best to change? I would expect that an IDE knows where to find the libraries it installed on my system. Is there really a requirement to add it to the project? Or did I miss something?

    With kind regards,

    Konrad

  2. #2
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: How to add the hamcrest library?

    Just in case someone else ran into this trouble:

    - I added the library to source control first and added it to the project. But I didn't like that idea that much because the library is only required during development. But it worked fine. (And maybe that solution is the correct one regarding build servers. But I am not that far right now!)
    - So what I did today. I removed the libraries from source control and instead created a local directory with all jar files inside. And then I added the jars in there as global libraries.

    So I am still interested in best practices in case someone has more experience with IntelliJ (maybe including build servers).

    With kind regards,

    Konrad

Similar Threads

  1. Replies: 2
    Last Post: 03-03-2014, 07:48 PM
  2. Mp4 Library
    By kingler112 in forum Advanced Java
    Replies: 1
    Last Post: 04-27-2010, 03:54 PM
  3. I want to put the native library in library path in mac os x
    By Hussain Ali in forum Advanced Java
    Replies: 2
    Last Post: 02-24-2010, 08:55 AM
  4. Tell me jar file for library library org.bouncycastle.cms
    By 82rathi.angara in forum New To Java
    Replies: 10
    Last Post: 09-09-2008, 06:11 AM
  5. use a .dll library
    By Ed in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 04:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •