owlcs / owlapi

OWL API main repository
822 stars 315 forks source link

Runtime exception when using OWL API #1037

Closed Loanho314 closed 2 years ago

Loanho314 commented 2 years ago

Hi all,

I have the following (possibly a newbie) problem when creating OWLOntologyManager. Any idea or workaround? IDE: Eclipse, Java 1.8

When creating an OWLOntologyManager (code below):

public static void main(String[] args) throws OWLOntologyCreationException {
        OWLOntologyManager manager =OWLManager.createOWLOntologyManager();
               File inputOntologyFile = new File(path);
         OWLOntology ontology = manager.loadOntologyFromOntologyDocument(inputOntologyFile);**

I got the following exception in runtime: Exception in thread "main" java.lang.ExceptionInInitializerError at com.google.inject.internal.cglib.reflect.$FastClass$Generator.getProtectionDomain(FastClass.java:73) at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:206) at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:65) at com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:252) at com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:203) at com.google.inject.internal.ProviderMethod.create(ProviderMethod.java:69) at com.google.inject.internal.ProviderMethodsModule.createProviderMethod(ProviderMethodsModule.java:275) at com.google.inject.internal.ProviderMethodsModule.getProviderMethods(ProviderMethodsModule.java:144) at com.google.inject.internal.ProviderMethodsModule.configure(ProviderMethodsModule.java:123) at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340) at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:349) at com.google.inject.spi.Elements.getElements(Elements.java:110) at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:138) at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104) at com.google.inject.Guice.createInjector(Guice.java:99) at com.google.inject.Guice.createInjector(Guice.java:73) at com.google.inject.Guice.createInjector(Guice.java:62) at org.semanticweb.owlapi.apibinding.OWLManager.createInjector(OWLManager.java:104) at org.semanticweb.owlapi.apibinding.OWLManager.createOWLOntologyManager(OWLManager.java:44) at com.mycompany.owl.Load.main(Load.java:23) Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @5c072e3f at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199) at java.base/java.lang.reflect.Method.setAccessible(Method.java:193) at com.google.inject.internal.cglib.core.$ReflectUtils$1.run(ReflectUtils.java:52) at java.base/java.security.AccessController.doPrivileged(AccessController.java:318) at com.google.inject.internal.cglib.core.$ReflectUtils.(ReflectUtils.java:42) ... 20 more

ignazio1977 commented 2 years ago

Hi, can you add the OWLAPI version you're using?

The stack trace (seems to) point out to the Guice library attempting reflective operations that aren't allowed on this VM - but the exception mentioned is about java.base and java.lang modules. This suggests it's not runnng on Java 8, rather Java 9 or newer. Can you double check what's your runtime?

The latest OWLAPI builds don't use Guice any longer, hence my question about OWLAPI version. You should be able to just use a newer version to resolve the problem.

Loanho314 commented 2 years ago

Hi, here is OWL API I that I am using

**

        <groupId>net.sourceforge.owlapi</groupId>
        <artifactId>owlapi-distribution</artifactId>
        <version>5.1.0</version>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.owlapi</groupId>
        <artifactId>org.semanticweb.hermit</artifactId>
        <version>1.3.8.510</version>
    </dependency>**### 
ignazio1977 commented 2 years ago

There's a HermiT 1.4.5.519 - OWLAPI 5 compatible, includes some minor bug fixes (compared with 1.3.8).

Guice was removed from version 5.1.6 on, the latest version being 5.1.19. I expect the HermiT build to work with the latest version. That should also fix the error you're seeing.