0

清理后,当我尝试构建 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 文件。我只能看到访问规则:没有定义规则和本机库位置:(无)

4

1 回答 1

0

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

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

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

然后你必须从你上面提到的那个文件夹中添加哪个jar(即libs)

dependencies {
  compile 'gson-0.1.0'
}
于 2018-11-15T11:03:09.553 回答