java.lang.ClassNotFoundException: org.json.JSONException

zwl*_*tor 5 maven java.lang.class jsonexception

我正在构建一个简单的 Maven 项目。我使用构建路径添加json为第三方库,并将其添加到web-inf库中。最后,我在pom.xml. 然而,经过上述所有努力,我仍然遇到这个异常。任何信息和建议表示赞赏!

下面是例外情况

SEVERE: Servlet.service() for servlet [sfmserver] in context with path [/mysfmovies] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.json.JSONException
Run Code Online (Sandbox Code Playgroud)

下面是我的pom.xml的内容

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mysfmovies</groupId>
  <artifactId>mysfmovies</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>mysfmovies Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
      <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
    </dependency>
            <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20090211</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.geocoder-java</groupId>
            <artifactId>geocoder-java</artifactId>
            <version>0.16</version>
            <scope>provided</scope>
        </dependency>
  </dependencies>
  <build>
    <finalName>mysfmovies</finalName>
  </build>
</project>
Run Code Online (Sandbox Code Playgroud)

Rag*_*air 6

您可以解决此问题添加以下依赖项(http://mvnrepository.com/artifact/org.json/json/20080701

<dependency>
   <groupId>org.json</groupId>
   <artifactId>json</artifactId>
   <version>20080701</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)


mil*_*anm 0

您已将所有依赖项放入提供的范围内。这意味着 Maven War 插件不会将它们放入 WEB-INF/lib 目录中,因此当您运行 Web 应用程序时它们不会出现在类路径上。您确实应该将它们放入编译范围(这是默认范围,只需删除标签)。

如果您仍然确实希望提供它们,请将它们放入容器的 lib 目录中,或检查 war 插件的 EndorsedDirs 配置。