1

I've a new grails 2.0 project and i want to integrate HtmlUnit-Libraries into it. I just moved the HtmlUnit 2.9 libs into the "lib"-Folder of my grails project and used them in my grails-service. When i start my application, using intelliJ 11 IDE, it doesn't start because grails can't find the imports.

In my Service class i did:

 import com.gargoylesoftware.htmlunit.WebClient
 import com.gargoylesoftware.htmlunit.BrowserVersion

After starting the grails run-app script, i get the following exception:

/Users/whitenexx/Workspaces/sts-workspace/OMTool/grails-app/services/omtool/TestService.groovy: 4: unable to resolve class com.gargoylesoftware.htmlunit.BrowserVersion
@ line 4, column 1.
import com.gargoylesoftware.htmlunit.BrowserVersion^

How do I integrate java-libraries into an grails project?

ataylor
  • 64,891
  • 24
  • 161
  • 189
whitenexx
  • 1,350
  • 2
  • 25
  • 53

3 Answers3

4

Instead of copying the jar into the /lib directory, try specifying it in BuildConfig.groovy

grails.project.dependency.resolution = {

    // inherit Grails' default dependencies
    inherits("global") {
        // uncomment to disable ehcache
        // excludes 'ehcache'
    }
    log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    checksums true // Whether to verify checksums on resolve

    repositories {
        inherits true // Whether to inherit repository definitions from plugins
        grailsPlugins()
        grailsHome()
        grailsCentral()

        mavenLocal()
        mavenCentral()

    }
    dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
        compile 'net.sourceforge.htmlunit:htmlunit:2.9'
    }
}
Dónal
  • 185,044
  • 174
  • 569
  • 824
1

I encountered the same problem,solved already. specifying it in BuildConfig.groovy.

dependencies {

    compile('net.sourceforge.htmlunit:htmlunit:2.9') {
        excludes 'xml-apis' 
    }
}

if not take effect,you can clean your grails ivy-cache first and try it again.

chloe
  • 11
  • 1
1

Did you add the jars to your buildpath?

  • That's the problem. In eclipse/sts is an contextoption called "buildpath". I can't find a similar option in intelliJ. Or do i have to edit the buildpath elsewhere? – whitenexx Dec 19 '11 at 17:47
  • This isn't the same thing you are looking at but they explain how to do that here http://stackoverflow.com/questions/5533428/how-to-add-a-jar-to-my-lib-directory-in-intellij-and-have-the-classes-available –  Dec 19 '11 at 17:50
  • Hmmm..I'm not an idea user so I can't play around with it. Are any other classes being used from those packages giving you trouble? Maybe it is just that .jar... –  Dec 19 '11 at 18:07
  • When i use plain grails without IDE, it should work? I would like to use sts/eclipse but the newest grails 2.0 isn't supported yet. – whitenexx Dec 19 '11 at 18:23
  • Should work. I use netbeans for my grails development and it's pretty nice. I only use plugins to use functionality though..not sure if this will help your issue but but it looks like you aren't suppose to include the xml-apis-*.jar in your classpath when you use HtmlUnit with grails. –  Dec 19 '11 at 18:37
  • You don't have to care about "buildpath", all jars in '/lib' folder will automatically added to "buildpath". – Sergey Dec 20 '11 at 10:34