1

I've been looking for two days to integrate Apache Jena in a Web Application that uses PrimeFaces (open source framework for JavaServerFaces). The project is built using Apache Maven and deployed locally in "operating mode: standalone" to WildFly 12 application server.

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>

I have created an IndexView backing Bean with an init method, annotated with @PostConstruct. Everything works fine without calling Jena API.

On adding to init method this simple line

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

these exception are thrown:

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 file is included in jena-core dependency (included in jena-arq dependency)
  • All dependencies are included in classpath and in the generated war (I can see them under the lib folder in the generated artifact).

I cannot figure out how to make it work.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
AGL
  • 116
  • 1
  • 7
  • Hi, how is this PrimeFaces related (other than you using it) Does creating a new small webapp without PrimeFaces make it work?. And your usage of Maven is wrong, you should (almost) never include the jsf or any java-ee api jar with another scope than 'provided'. – Kukeltje Jan 04 '19 at 14:53
  • I've just removed the PrimeFaces dependency and add `provided` to Servlet and JSF dependencies. The error is exactly the same. – AGL Jan 04 '19 at 15:01
  • Great, it is at least an improvement and shows it is not PF related. And I assume there is more info in the full stacktrace server side. This looks like the info in the screen on the browser and it looks like the constructor of a class cannot be executed. Most likely 100% jena related. Did you post the full error in a search engine? – Kukeltje Jan 04 '19 at 15:02
  • Yes I've posted it. It seems that the war doesn't contains Jena dependencies (but these are contained under `out -> artifact -> my_war_exploded -> WEB-INF -> lib` . I've read a lot of questions and answers here like that one [link](https://stackoverflow.com/questions/5443580/using-jena-api-in-java-web-unknown-exception) or [link](https://stackoverflow.com/questions/6083501/maven-dependencies-not-visible-in-web-inf-lib) but nothing works. I'm using IntelliJ Ultimate as IDE. – AGL Jan 04 '19 at 15:52
  • So try to fix that. Effectively not a jsf related thing (nor wildfly), but more likely a maven related issue – Kukeltje Jan 04 '19 at 16:11
  • Using `jena-arq` version `2.11.0` it works. But it's a very old version (Sept 2013). – AGL Jan 08 '19 at 10:52
  • So maybe you have some old way of using jena that needs updating for the newer version. And the error suggests there is an error in the loading of `file:location-mapping.rdf` Search for the solution to that... – Kukeltje Jan 08 '19 at 10:57
  • I'm searching for that error. Thank you for answering :) – AGL Jan 08 '19 at 11:29

0 Answers0