我是 JAVA 的初学者,我正在使用 Apache Tomcat 在 Eclipse Neon 上开发一个 Web 应用程序。我编写了 search.jsp 文件,这是一小部分:
<%@page import="cercaPattern.*, searchPattern.*, fuzzydl.exception.*,fuzzydl.parser.*"%>
<%
Cerca ricerca = new Cerca();
try
{
ricerca.cercaPattern();
Search cerca = new Search();
cerca.cercaPattrn();
}
catch (InconsistentOntologyException exc)
{
exc.printStackTrace();
}
catch (FuzzyOntologyException exc)
{
exc.printStackTrace();
}
catch (ParseException exc)
{
exc.printStackTrace();
}
但是我认为不需要引入fuzzydl.exception.* 和fuzzydl.parser.*。我有这个错误:
HTTP Status 500 - Unable to compile class for JSP:
type Exception report
message Unable to compile class for JSP:
description The server encountered an internal error that prevented it
from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 58 in the jsp file: /search.jsp The type
fuzzydl.exception.InconsistentOntologyException cannot be resolved. It
is indirectly referenced from required .class files 55: try 56:
{ 57: 58: ricerca.cercaPattern(); 59: Search cerca = new Search(); 60: cerca.cercaPattrn(); 61: }
An error occurred at line: 58 in the jsp file: /search.jsp The type
fuzzydl.exception.FuzzyOntologyException cannot be resolved. It is
indirectly referenced from required .class files 55: try 56:
{ 57: 58: ricerca.cercaPattern(); 59: Search cerca = new Search(); 60: cerca.cercaPattrn(); 61: }
An error occurred at line: 58 in the jsp file: /search.jsp The type
fuzzydl.parser.ParseException cannot be resolved. It is indirectly
referenced from required .class files 55: try 56: { 57:
58: ricerca.cercaPattern(); 59: Search cerca = new Search(); 60: cerca.cercaPattrn(); 61: }
An error occurred at line: 58 in the jsp file: /search.jsp The method
cercaPattern() from the type Cerca refers to the missing type
ParseException 55: try 56: { 57: 58:
ricerca.cercaPattern(); 59: Search cerca = new Search(); 60: cerca.cercaPattrn(); 61: }
An error occurred at line: 63 in the jsp file: /search.jsp
InconsistentOntologyException cannot be resolved to a type 60:
cerca.cercaPattrn(); 61: } 62: 63: catch (InconsistentOntologyException exc) 64: { 65:
exc.printStackTrace(); 66: }
An error occurred at line: 67 in the jsp file: /search.jsp
FuzzyOntologyException cannot be resolved to a type 64: { 65:
exc.printStackTrace(); 66: } 67: catch (FuzzyOntologyException exc) 68: { 69:
exc.printStackTrace(); 70: }
An error occurred at line: 71 in the jsp file: /search.jsp
ParseException cannot be resolved to a type 68: { 69:
exc.printStackTrace(); 70: } 71: catch (ParseException exc) 72: { 73: exc.printStackTrace(); 74: }
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:212)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:377)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:333)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:600)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:368)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
我不明白这一点,因为我添加了一个外部 FuzzyDL.jar 文件,其中包含包含 3 个文件 .class 的 2 个包,如图所示:
Cerca.java 的代码是这样的:
package searchPattern;
import java.io.*;
import java.util.*;
import fuzzydl.*;
import fuzzydl.exception.*;
import fuzzydl.milp.*;
import fuzzydl.parser.*;
import fuzzydl.util.*;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.PrefixManager;
import org.semanticweb.owlapi.util.DefaultPrefixManager;
public class Cerca
{
public void cercaPattern () throws IOException, OWLOntologyCreationException, ParseException, FuzzyOntologyException, InconsistentOntologyException
{
System.out.println("palo0");
ConfigReader.loadParameters("CONFIG", new String[0]);
System.out.println("palo1");
Parser parser = new Parser(new FileInputStream("C:\\Users\\Salvatore\\workspace\\progetto_per_ISA\\WebContent\\WEB-INF\\architecturalpatterns2.txt"));
System.out.println("palo2");
parser.Start();
System.out.println("palo3");
KnowledgeBase kb = Parser.getKB("C:\\Users\\Salvatore\\workspace\\progetto_per_ISA\\WebContent\\WEB-INF\\architecturalpatterns.owl");
System.out.println("palo4");
kb.saveToFile("C:\\Users\\Salvatore\\workspace\\progetto_per_ISA\\WebContent\\WEB-INF\\ontologyoutput.txt");
System.out.println("palo5");
}
}
此外,Eclipse 中的控制台不显示字符串“palo0”和 Cerca.java 中包含的其他字符串。