简体   繁体   English

我在 Netbeans IDE 上运行 JSP 和 Servlet 时遇到问题

[英]I got problem to run JSP and Servlet on Netbeans IDE

I got a problem to run JSP file on Apache Netbeans 12.3 JDK 16.0 and I am using tomcat 9.0.45 on macOS BigSur. I got a problem to run JSP file on Apache Netbeans 12.3 JDK 16.0 and I am using tomcat 9.0.45 on macOS BigSur. I'm not sure what is the problem actually.我不确定实际上是什么问题。 Could you please help me.And when I run the servlet file I got this error message.你能帮帮我吗?当我运行 servlet 文件时,我收到了这个错误消息。

java.lang.IllegalAccessError: class org.netbeans.modules.tomcat5.deploy.TomcatManagerImpl (in unnamed module @0x19f724b9) cannot access class com.sun.org.apache.xerces.internal.impl.dv.util.Base64 (in module java.xml) because module java.xml does not export com.sun.org.apache.xerces.internal.impl.dv.util to unnamed module @0x19f724b9
    at org.netbeans.modules.tomcat5.deploy.TomcatManagerImpl.run(TomcatManagerImpl.java:533)
    at org.netbeans.modules.tomcat5.deploy.TomcatManagerImpl.list(TomcatManagerImpl.java:372)
    at org.netbeans.modules.tomcat5.deploy.TomcatManager.modules(TomcatManager.java:718)
    at org.netbeans.modules.tomcat5.deploy.TomcatManager.getAvailableModules(TomcatManager.java:529)
    at org.netbeans.modules.tomcat5.optional.TMIDResolver.lookupTargetModuleID(TMIDResolver.java:56)
    at org.netbeans.modules.j2ee.deployment.impl.TargetServer.checkUndeployForSharedReferences(TargetServer.java:349)
    at org.netbeans.modules.j2ee.deployment.impl.TargetServer.checkUndeployForSharedReferences(TargetServer.java:322)
    at org.netbeans.modules.j2ee.deployment.impl.TargetServer.checkUndeployForSharedReferences(TargetServer.java:319)
    at org.netbeans.modules.j2ee.deployment.impl.TargetServer.processLastTargetModules(TargetServer.java:440)
    at org.netbeans.modules.j2ee.deployment.impl.TargetServer.init(TargetServer.java:170)
    at org.netbeans.modules.j2ee.deployment.impl.TargetServer.deploy(TargetServer.java:605)
    at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:221)
    at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:141)
    at org.netbeans.modules.j2ee.ant.Deploy.execute(Deploy.java:86)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at jdk.internal.reflect.GeneratedMethodAccessor59.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
    at org.apache.tools.ant.Task.perform(Task.java:350)
    at org.apache.tools.ant.Target.execute(Target.java:449)
    at org.apache.tools.ant.Target.performTasks(Target.java:470)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1391)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1254)
    at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:261)
    at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:574)
    at org.netbeans.core.execution.RunClassThread.doRun(RunClassThread.java:132)
    at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
    at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
    at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:81)

In Java 9, the Java Platform Module System has been introduced.在 Java 9 中,引入了 Java 平台模块系统。

This also adds access rules.这也增加了访问规则。

In your case, the module java.xml does not export com.sun.org.apache.xerces.internal.impl.dv.util.Base64 but tomcat tries to access it nevertheless (The version of tomcat you are using may not support JPMS). In your case, the module java.xml does not export com.sun.org.apache.xerces.internal.impl.dv.util.Base64 but tomcat tries to access it nevertheless (The version of tomcat you are using may not support JPMS )。

Here are three different approaches you could try:您可以尝试以下三种不同的方法:

Update Tomcat更新 Tomcat

Newer versions of tomcat might have fixed this issue.较新版本的 tomcat 可能已修复此问题。 For example, tomcat 10 seems to support JPMS.例如,tomcat 10 似乎支持 JPMS。

Add --add-exports java.xml/com.sun.org.apache.xerces.internal.impl.dv.util=ALL-UNNAMED to the JVM arguments. Add --add-exports java.xml/com.sun.org.apache.xerces.internal.impl.dv.util=ALL-UNNAMED to the JVM arguments.

When starting tomcat, you can add the JVM argument --add-exports java.xml/com.sun.org.apache.xerces.internal.impl.dv.util=ALL-UNNAMED to the command that starts tomcat. When starting tomcat, you can add the JVM argument --add-exports java.xml/com.sun.org.apache.xerces.internal.impl.dv.util=ALL-UNNAMED to the command that starts tomcat. As tomcat is likely started via a script, this behaviour might be controlled with environment variables.由于 tomcat 可能是通过脚本启动的,因此此行为可能由环境变量控制。 Many scripts use the environment variable JAVA_OPTS for this.许多脚本为此使用环境变量JAVA_OPTS If you set the environment variable JAVA_OPTS to --add-exports java.xml/com.sun.org.apache.xerces.internal.impl.dv.util=ALL-UNNAMED (or add that to the environment variable) before starting tomcat, it might get picked up. If you set the environment variable JAVA_OPTS to --add-exports java.xml/com.sun.org.apache.xerces.internal.impl.dv.util=ALL-UNNAMED (or add that to the environment variable) before starting tomcat ,它可能会被捡起。 Alternatively, you can manually add it to the command or use an environment variable like JAVA_TOOL_OPTIONS that gets picked up by the JVM automatically.或者,您可以手动将其添加到命令中,或使用 JVM 自动获取的环境变量(如JAVA_TOOL_OPTIONS )。

This configures the module java.xml to export the package to all unnamed modules (including tomcat) even if it does not do that by default.这会将模块 java.xml 配置为将 package 默认导出到所有未命名的模块(包括 tomcat)。

See Java Platform, Standard Edition Oracle JDK 9 Migration Guide请参阅Java 平台,标准版 Oracle JDK 9 迁移指南

If you need to use an internal API that has been made inaccessible, then use the --add-exports runtime option.如果您需要使用无法访问的内部 API,请使用--add-exports运行时选项。 You can also use --add-exports at compile time to access internal APIs.您还可以在编译时使用--add-exports来访问内部 API。

See the docs on details what --add-exports does.有关--add-exports功能的详细信息,请参阅文档

Remove the module-info.java删除module-info.java

By doing this, Java could fall back to the old non-JPMS behaviour.通过这样做,Java 可能会退回到旧的非 JPMS 行为。

NetBeans 12.3 does not support JDK 16, so what you were attempting to do is unsupported. NetBeans 12.3 不支持 JDK 16,因此您尝试执行的操作不受支持。

Refer to the section on Deployment Platforms in the NetBeans 12.3 documentation:请参阅 NetBeans 12.3 文档中有关部署平台的部分:

Apache NetBeans 12.3 runs on JDK LTS releases 8 and 11, as well as on JDK 15, ie, the current JDK release at the time of this NetBeans release. Apache NetBeans 12.3 在 JDK LTS 版本 8 和 11 以及 JDK 15 上运行,即在此 Z69F0F6923BC1F8AAA26B86Z82AFDB 发布时的当前 JDK 版本。

So try replacing JDK 16 in your NetBeans configuration with JDK 15, to see if the problem goes away.因此,请尝试将 NetBeans 配置中的 JDK 16 替换为 JDK 15,看看问题是否消失。 If the issue persists using Java 15 then update your question by replacing the JDK 16 stack trace with a JDK 15 stack trace.如果使用 Java 15 问题仍然存在,则通过将 JDK 16 堆栈跟踪替换为 JDK 15 堆栈跟踪来更新您的问题。

As a related matter, since you mentioned that you are using Big Sur, you may also want to review NetBeans Bug Report NETBEANS-5037 NetBeans dialog windows in Big Sur .作为一个相关的问题,既然您提到您正在使用 Big Sur,您可能还想查看 NetBeans 错误报告NETBEANS-5037 NetBeans 对话框 windows 在 Big Sur中。 That may not be relevant for you, but it is also mentioned in the NetBeans 12.3 release documentation:这可能与您无关,但 NetBeans 12.3 版本文档中也提到了它:

The current JDKs have an issue on macOS Big Sur, that causes freezes on dialogs.当前的 JDK 在 macOS Big Sur 上存在问题,导致对话框冻结。 That could be fixed by applying the workaround described at NETBEANS-5037.这可以通过应用 NETBEANS-5037 中描述的解决方法来解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM