gpt4 book ai didi

java - JSP - 只能导入一个类型。 Name.pacakge.class 解析为一个包,但类在那里

转载 作者:行者123 更新时间:2023-11-28 22:49:53 25 4
gpt4 key购买 nike

我在尝试通过 tomcat 7 部署 Web 应用程序时收到此错误。

jsp 文件名 analysis.jsp 这是错误:

Apr 05, 2017 3:05:39 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet [analyserServlet] in web application [/MWE] threw load() exception
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: [26] in the generated java file: [/usr/share/tomcat/work/Catalina/localhost/MWE/org/apache/jsp/analysis_jsp.java]
Only a type can be imported. mila.HMM.MorphMult2TaggerFormat resolves to a package

An error occurred at line: [27] in the generated java file: [/usr/share/tomcat/work/Catalina/localhost/MWE/org/apache/jsp/analysis_jsp.java]
Only a type can be imported. mila.HMM.HMM2Morph resolves to a package

An error occurred at line: [28] in the generated java file: [/usr/share/tomcat/work/Catalina/localhost/MWE/org/apache/jsp/analysis_jsp.java]
Only a type can be imported. mila.mw.PostProcessor1 resolves to a package

An error occurred at line: [29] in the generated java file: [/usr/share/tomcat/work/Catalina/localhost/MWE/org/apache/jsp/analysis_jsp.java]
Only a type can be imported. mila.mw.MWXMLTokenizer resolves to a package

An error occurred at line: 36 in the jsp file: /analysis.jsp
mila.mw.MWXMLTokenizer cannot be resolved to a type
33: String tokenizeAndAnalyze(String rawText) throws Exception {
34: StringWriter sw = new StringWriter();
35: try (InputStream ins = new ByteArrayInputStream(rawText.getBytes("UTF-8"))) {
36: new mila.mw.MWXMLTokenizer().tokenizeAndAnalyze(ins, new PrintWriter(sw));
37: }
38: StringWriter ppSW = new StringWriter();
39: try (InputStream ins = new ByteArrayInputStream(sw.toString().getBytes("UTF-8"))) {


An error occurred at line: 40 in the jsp file: /analysis.jsp
mila.mw.PostProcessor1 cannot be resolved to a type
37: }
38: StringWriter ppSW = new StringWriter();
39: try (InputStream ins = new ByteArrayInputStream(sw.toString().getBytes("UTF-8"))) {
40: new mila.mw.PostProcessor1().process(ins, new PrintWriter(ppSW));
41: }
42: return ppSW.toString();
43: }


An error occurred at line: 46 in the jsp file: /analysis.jsp
mila.HMM.MorphMult2TaggerFormat cannot be resolved to a type
43: }
44:
45: String runTagger(String xmlAnalyzed, String _tempDirectoryPath) throws Exception {
46: final String taggerFormat = new mila.HMM.MorphMult2TaggerFormat()
47: .myWEBMorp2Tagger(xmlAnalyzed, _tempDirectoryPath);
48: final String roydir = "/data/tagger/royTagger/";
49: final String probabilityDir = "/data/tagger/taggerLearningOutputFile/";


An error occurred at line: 60 in the jsp file: /analysis.jsp
mila.HMM.HMM2Morph cannot be resolved to a type
57:
58: final String xmlTaggedFilename = _tempDirectoryPath + "/tagged.xml";
59: PrintWriter pw = new PrintWriter(xmlTaggedFilename);
60: new mila.HMM.HMM2Morph().process(xmlAnalyzed, taggedFilename, pw);
61: return xmlTaggedFilename;
62: }
63:


Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:494)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:379)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.init(JspServlet.java:138)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1282)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1195)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1085)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5318)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5610)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1260)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:2002)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

这是从 jsp 导入的部分:

<%@ page language = "java"
import = "java.lang.StringBuilder"
import = "java.io.StringWriter"
import = "java.io.PrintWriter"
import = "java.io.ByteArrayInputStream"
import = "java.io.IOException"
import = "java.io.File"
import = "java.io.BufferedReader"
import = "java.io.InputStreamReader"
import = "java.io.InputStream"
import = "java.nio.file.Files"
import = "java.nio.file.Paths"
import = "java.nio.file.StandardCopyOption"
import = "mila.HMM.MorphMult2TaggerFormat"
import = "mila.HMM.HMM2Morph"
import = "mila.mw.PostProcessor1"
import = "mila.mw.MWXMLTokenizer"
%>

WEB-INF/lib 文件夹下,我有一个名为 morphAnalyzer.jar 的 JAR,它基本上就是项目,它包含所有需要的类,包括导致的类这个错误。这是对 JAR 的部分 vim 查看

mila/
mila/HMM/
mila/HMM/HMM2Morph.class
mila/HMM/MorphMult2TaggerFormat.class
...
mila/mw/MWXMLMorphAnalyzer.class
mila/mw/MWXMLTokenizer.class
mila/mw/PostProcessor1.class
...

如您所见,jar 确实包含我需要的所有类,但出于某种原因,jsp 文件无法将它们识别为类。

P.S 没有其他包的类名相同(即所有类名在整个项目中都是唯一的)

我做错了什么?请帮忙。

最佳答案

在您的应用程序的类路径中包含 morphAnalyzer.jar

关于java - JSP - 只能导入一个类型。 Name.pacakge.class 解析为一个包,但类在那里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43231270/

25 4 0