java - 无法在eclipse中构建gradle项目?

标签 java eclipse gradle build.gradle buildship

清理后,当我尝试构建 gradle 时,我在控制台中收到错误消息:

包 org.json 不存在导入 org.json.JSONObject;

找不到标志
符号:类 JSONObject

java文件中所有jsonobject和json数组存在的地方都有红色标记。

我已将包含所有 jar 文件的文件夹 web inf/lib 放在我创建的 src/main/webapp 目录中。

目前我的 build.gradle 文件的内容是:

/*
 * This build file was auto generated by running the Gradle 'init' task
 * by 'i2cdev001' at '14/11/18 3:11 PM' with Gradle 2.14.1
 *
 * This generated file contains a sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * user guide available at https://docs.gradle.org/2.14.1/userguide/tutorial_java_projects.html
 */

// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'war'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

// In this section you declare the dependencies for your production and test code
dependencies {
    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.21'

    // Declare the dependency for your favourite test framework you want to use in your tests.
    // TestNG is also supported by the Gradle Test task. Just change the
    // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
    // 'test.useTestNG()' to your build script.
    testCompile 'junit:junit:4.12'
}

注意:同样在项目属性中,我无法在 java 构建路径选项卡中的 Web App Libraries 下看到任何 jar 文件。我只能看到访问规则:没有定义规则和 native 库位置:(无)

最佳答案

由于您的项目是 gradle 项目,因此手动添加 jar 将不起作用。您必须提及将所有 jar 文件保存在 build.gradle 文件中的路径。

在 flatDir {} 下的存储库中提及您的 jar 文件路径:

repositories {
  jcenter()
  flatDir {
   dirs 'libs'
  }
}

然后你必须从你上面提到的那个文件夹中添加哪个jar(即libs)
dependencies {
  compile 'gson-0.1.0'
}

关于java - 无法在eclipse中构建gradle项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53317817/

相关文章:

java - 使用 Ruby 与 jRuby 的设计问题

java - 试图为Java(JSP)中的随机数设置范围,但我不确定如何处理

eclipse - 有人可以向我解释 Maven 2(或 3)依赖解析吗?

gradle - 如何在gradle中获取JavaExec任务的classes任务以依赖于另一个任务?

java - 如何使用 gradle 启动交互式 Java 应用程序

java - 谁能解释一下我的 Apache Spark 错误 SparkException : Job aborted due to stage failure

在没有 Eclipse 的情况下使用 tess4j 出现 java.lang.NoClassDefFoundError

eclipse - 我可以将 Eclipse 设置为只为当前项目发出错误、警告等吗?

Gradle Copy 任务说没有来源

java - 匿名用户的 Tomcat/spring session 管理