Question

I'm very new to Gradle and the main reason I use it because I need to resolve dependencies issues for my compiled jar.

Here is my build.gradle file:

apply plugin: 'java'
apply plugin: 'eclipse'

version = '0.9'

jar {
    manifest {
      attributes 'Main-Class': 'wd.nlp.FileImport', 'Implementation-Title': 'WD\
NLP', 'Implementation-Version': version
    }
}

repositories {
    flatDir(dirs: 'lib')
}

dependencies{
    compile 'mallet:mallet:2.0.7'
}

My Java files all depend on a third-party library called Mallet. Here is my folder structure:

 |---1.10
 |-----taskArtifacts
 |-build
 |---classes
 |-----main
 |-------wd
 |---------nlp
 |---dependency-cache
 |---libs
 |---tmp
 |-----jar
 |-lib
 |-src
 |---main
 |-----java
 |-------wd
 |---------nlp
 |-----resources

I placed Mallet-2.0.7.jar inside lib under the top folder. Then I used gradle build command and try to run my class:

java -classpath build/libs/JavaClassifier-0.9.jar wd.nlp.FileImport -train ...

Then I am told:

Exception in thread "main" java.lang.NoClassDefFoundError: cc/mallet/pipe/Pipe
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)

The Mallet library's path is cc.mallet.*...and now I don't know what to do...please help!

Was it helpful?

Solution

The dependency is not include because you don't create a distribution of you project. In Maven it is called an assembly.

If you call your application directly from the commandline it is not a matter of Gradle.

Anyway there is a Gradle plugin which creates a distribution and adds shell scripts to execute your application.

So when you add the following line to the gradle script.

apply plugin: 'application'

you will get some new tasks to create a distribution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top