gpt4 book ai didi

java - 如何在模块化java项目中使用嵌入式tomcat

转载 作者:行者123 更新时间:2023-12-01 14:33:09 26 4
gpt4 key购买 nike

我想创建一个包含内部 tomcat 服务器的 java 模块化项目。我可以很容易地在非模块化 java 中使用嵌入式 tomcat 服务器,但是 web 它涉及到模块,它有很多错误。
这是我的 module-info.java 文件

module RunMe{
requires tomcat.embed.core;
requires annotations.api;
}

当我运行最简单的tomcat服务器代码时,它给了我这个:
Nov 12, 2019 10:08:26 AM org.apache.catalina.core.StandardContext setPath
WARNING: A context path must either be an empty string or start with a '/' and do not end with a '/'. The path [/] does not meet these criteria and has been changed to []
Nov 12, 2019 10:08:27 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8571"]
Nov 12, 2019 10:08:27 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Nov 12, 2019 10:08:27 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Tomcat]
Nov 12, 2019 10:08:27 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/9.0.11
Nov 12, 2019 10:08:27 AM org.apache.catalina.loader.WebappLoader startInternal
SEVERE: LifecycleException
java.lang.NoClassDefFoundError: java/lang/instrument/IllegalClassFormatException
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:333)
at tomcat.embed.core/org.apache.catalina.loader.WebappLoader.createClassLoader(WebappLoader.java:503)
at tomcat.embed.core/org.apache.catalina.loader.WebappLoader.startInternal(WebappLoader.java:388)
at tomcat.embed.core/org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at tomcat.embed.core/org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4955)
at tomcat.embed.core/org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at tomcat.embed.core/org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1429)
at tomcat.embed.core/org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at tomcat.embed.core/org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
at tomcat.embed.core/org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:944)
at tomcat.embed.core/org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839)
at tomcat.embed.core/org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at tomcat.embed.core/org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1429)
at tomcat.embed.core/org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at tomcat.embed.core/org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
at tomcat.embed.core/org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:944)
at tomcat.embed.core/org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:261)
at tomcat.embed.core/org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at tomcat.embed.core/org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
at tomcat.embed.core/org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at tomcat.embed.core/org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
at tomcat.embed.core/org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at tomcat.embed.core/org.apache.catalina.startup.Tomcat.start(Tomcat.java:370)
at RunMe/test.RunMe.main(RunMe.java:48)
Caused by: java.lang.ClassNotFoundException: java.lang.instrument.IllegalClassFormatException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 29 more

最佳答案

很抱歉复活一个老问题,但我没有看到答案。也许这会帮助其他人。
将以下内容添加到您的 module-info.java 文件中:

requires java.instrument;

关于java - 如何在模块化java项目中使用嵌入式tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58813878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com