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

时间:2017-04-05 12:30:43

标签: java jsp tomcat web-deployment

我在尝试通过tomcat 7部署webapp时收到此错误。

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没有其他包名称相同的类(即所有类名在整个项目中都是唯一的)

我做错了什么?请帮忙。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

类在import属性中以逗号分隔。

如下所示:

import =“mila.HMM.MorphMult2TaggerFormat,mila.HMM.HMM2Morph,mila.mw.PostProcessor1,mila.mw.MWXMLTokenizer”