java - WebContent\WEB-INF\classes 文件夹为空。Java 构建路径找不到我的类
问题描述
我有 java.lang.ClassNotFoundException 错误。很简单,但我解决不了!
当我检查文件夹时
网页内容\WEB-INF\类
我看到它是空的。这意味着无法构建类。
我有一个 Maven 项目,我做了几次:Maven clean,Maven install,但我仍然有同样的错误。
当我查看我的 Java 构建路径窗口时,在源选项卡中,我看到默认输出文件夹是:MyProject/WebContent/WEB-INF/classes。同样在此窗口中,未选中复选框:允许源文件夹的输出文件夹,即使我选中并应用并保存它,当我运行项目时,它将再次自动取消选中。奇怪的!似乎还有其他东西正在重写我的构建路径。
您还可以在我的图片中看到我的 Web 部署程序集似乎是正确的。
我清理 Tomcat 服务器并清理项目并再次构建它。但这无济于事。
我的 web.xml 基于我的项目层次结构图像:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>SimBio</display-name>
<welcome-file-list>
<welcome-file>default.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>SimServlet</servlet-name>
<servlet-class>simbio.main.SimServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimServlet</servlet-name>
<url-pattern>/SimServlet</url-pattern>
</servlet-mapping>
</web-app>
我使用 Apache Tomcat 7.0,我的项目来到
HTTP 状态 500 - 实例化 servlet 类 simbio.main.SimServlet 时出错
异常
javax.servlet.ServletException:实例化 servlet 类 simbio.main.SimServlet 时出错
根本原因
java.lang.ClassNotFoundException:simbio.main.SimServlet
我的项目有什么问题。我还应该检查什么?
我会很感激你的帮助。
更新: 在环境变量中我有这些:
JAVA_HOME: C:\Program Files\Java\jre1.8.0_191
JAVA_PATH: C:\Program Files\Java\jre1.8.0_191\bin
Update2 我的 pom.xml (它取决于其他项目,如果在运行那些 Maven 依赖项项目时出现错误,我的项目可以生效吗?实际上我的项目是旧的,这些 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SimBio</groupId>
<artifactId>SimBio</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-model</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.github.sharispe</groupId>
<artifactId>slib-graph</artifactId>
<version>0.9.5</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.github.sharispe</groupId>
<artifactId>slib-graph-model</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>com.github.sharispe</groupId>
<artifactId>slib-utils</artifactId>
<version>0.9.5</version>
</dependency>
<dependency>
<groupId>com.github.sharispe</groupId>
<artifactId>slib-tools-sml-toolkit</artifactId>
<version>0.9.5</version>
</dependency>
<dependency>
<groupId>com.github.sharispe</groupId>
<artifactId>slib-sml</artifactId>
<version>0.9.5</version>
</dependency>
<dependency>
<groupId>com.github.sharispe</groupId>
<artifactId>slib-graph-algo</artifactId>
<version>0.9.5</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
Update3:我认为我的问题与其他依赖项目有关(目前无法安装他们的 maven。我的错误列表中有一个错误,即:构建路径不完整。
解决方案
它解决了!
我不知道什么对我有帮助,但我做了一些改变,总的来说它解决了我的问题:
- 无法建类时,项目的 pom.xml 和其他相关项目的 pom.xml 有错误。
- 当源文件夹的允许输出文件夹的复选框不能保持时,表示另一件事正在重写,因此请确保JAVA_HOME与项目设置相同
- 我还将输出文件夹添加为 MyProject/target/classes
- 我还检查了我的项目和其他相关项目中的 JDK/JRE 版本,并且 Tomcat 也相同。
- 我的 servlet 类上的编译错误也可能导致:Error instantiating servlet class
推荐阅读
- kubernetes - 在 application.properties 中定义/附加持久性卷声明
- java - Jshell从Powershell调用时显示混乱代码
- kubernetes - ClusterIP 服务没有在 Pod 之间平均分配流量
- r - R在嵌套的for循环中附加数据帧
- flutter - 渲染库捕获的异常 A RenderFlex 在右侧溢出了 98349 像素。相关的导致错误的小部件是 AppBar
- mysql - MySQL 5.7 对未知级别的层次结构数据的递归查询
- python - 如何确定 3D DataSet 样条插值的系数
- html - 滚动时,如果没有正文内容与导航重叠,就无法使用模糊过滤器使导航栏保持粘性?
- kubernetes - kubectl rollout status - 命令何时完成?
- java - 传递数组列表
从android本机代码到反应本机中的java脚本代码的bluetoothList