我遇到java.lang.ClassNotFoundException: com.arangodb.ArangoDB$Builder
错误,但不是在编译期间,而是在运行时。
完整的堆栈跟踪:
java.lang.NoClassDefFoundError: com/arangodb/ArangoDB$Builder
at dbmanager.ArangoDBManager.<init>(ArangoDBManager.java:12)
at dbmanager.DbManager.createExercise(DbManager.java:296)
at main.CreateProjectServlet.processRequest(CreateProjectServlet.java:34)
at main.CreateProjectServlet.doPost(CreateProjectServlet.java:21)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:417)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:754)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1376)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.arangodb.ArangoDB$Builder
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104)
... 28 more
我读过的东西(而且我读了很多东西),可能是由于编译期间存在运行时中缺少类而引起的。这样做有点道理,但是我没有找到解决方法。
当我从该类中的main调用该类(ArangoDBManager)时,它可以正常工作,因此问题必须在服务器上。
我正在使用Tomcat 9.0.4,Maven和Java 8。
我的pom.xml:
<groupId>groupId</groupId>
<artifactId>JavaEETomcat</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.45</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.arangodb</groupId>
<artifactId>arangodb-java-driver</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
我已经尝试了几种版本的arangodb-java-driver,但没有帮助。
处理ArangoDB的类:
import com.arangodb.ArangoDB;
import com.arangodb.entity.BaseDocument;
public class ArangoDBManager {
private final ArangoDB arangoDB;
static final String DB = "DP";
static final String COLLECTION = "user_exercise_files";
public ArangoDBManager() {
arangoDB = new ArangoDB.Builder().password("********").build();
}
public void insertDocument(BaseDocument document) {
arangoDB.db(DB).collection(COLLECTION).insertDocument(document);
}
public void deleteDocument(String key) {
arangoDB.db(DB).collection(COLLECTION).deleteDocument(key);
}
public BaseDocument getDocument(String key) {
return arangoDB.db(DB).collection(COLLECTION).getDocument(key,
BaseDocument.class);
}
在构造函数中生成错误。
我在类路径中有该类:module dependecies
如果我忘记了一些信息,请告诉我。
我希望有人有想法,我觉得我已经尝试了一切。
最佳答案
我认为您需要将arangodb-java-driver的类路径范围更改为Provided
关于java - java.lang.NoClassDefFoundError:com.arangodb.ArangoDB $ Builder Tomcat 9.0.4,Maven,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53213847/