简体   繁体   English

Jar中不包含Gradle依赖项

[英]Gradle Dependencies aren't included in jar

I'm very new to Gradle and the main reason I use it because I need to resolve dependencies issues for my compiled jar. 我是Gradle的新手,也是我使用它的主要原因,因为我需要解决已编译jar的依赖项问题。

Here is my build.gradle file: 这是我的build.gradle文件:

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 . 我的Java文件都依赖于名为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. 我将Mallet-2.0.7.jar放置在顶层文件夹下的lib Then I used gradle build command and try to run my class: 然后,我使用gradle build命令并尝试运行我的课程:

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! Mallet库的路径是cc.mallet.* ...现在我不知道该怎么办...请帮助!

The dependency is not include because you don't create a distribution of you project. 不包括依赖项,因为您没有创建项目的分发。 In Maven it is called an assembly. 在Maven中,它称为程序集。

If you call your application directly from the commandline it is not a matter of Gradle. 如果您直接从命令行调用应用程序,则不是Gradle的问题。

Anyway there is a Gradle plugin which creates a distribution and adds shell scripts to execute your application. 无论如何,有一个Gradle插件可以创建发行版并添加Shell脚本来执行您的应用程序。

So when you add the following line to the gradle script. 因此,当您将以下行添加到gradle脚本中时。

apply plugin: 'application'

you will get some new tasks to create a distribution. 您将获得一些创建分配的新任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM