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.