将Apache Jena集成到Web应用程序项目中时,出现NoClassDefFoundException

时间:2019-01-04 14:45:14

标签: maven wildfly jena

我一直在寻找两天时间,以将Apache Jena集成到使用PrimeFaces(JavaServerFaces的开源框架)的Web应用程序中。该项目使用Apache Maven构建,并以“操作模式:独立”本地部署到WildFly 12应用程序服务器。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
    http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>it</groupId>
    <artifactId>Test2</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <!-- JSF -->
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.15</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.15</version>
        </dependency>        
        <!-- PrimeFaces -->
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>6.1</version>
        </dependency>
        <!-- Jena -->
        <dependency>
            <groupId>org.apache.jena</groupId>
            <artifactId>jena-arq</artifactId>
            <version>3.9.0</version>            
        </dependency>
     </dependencies>
     <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
     </build>
</project>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
        http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
        version="4.0">
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
</web-app>

我用IndexView方法创建了一个init支持Bean,并用@PostConstruct进行了注释。无需调用Jena API,一切正常。

将简单的行添加到init方法中

OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);

这些异常被抛出:

javax.servlet.ServletException
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
...
Caused by: java.lang.ExceptionInInitializerError
    at org.apache.jena.ontology.OntModelSpec.<clinit>(OntModelSpec.java:49)
    at IndexView.init(IndexView.java:32)
...
Caused by: java.nio.file.InvalidPathException: Illegal char <:> at index 4: file:location-mapping.rdf
...
javax.servlet.ServletException: Could not initialize class org.apache.jena.ontology.OntModelSpec
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
...
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.jena.ontology.OntModelSpec
at IndexView.init(IndexView.java:32)
  • location-mapping.rdf文件包含在jena-core依赖项中(包含在jena-arq依赖项中)
  • 所有依赖项都包含在classpath和生成的war中(我可以在生成的工件的lib文件夹下看到它们)。

我不知道如何使它工作。

0 个答案:

没有答案
相关问题