owlcs / owlapi

OWL API main repository
813 stars 314 forks source link

[Question/Help] Could not find an ontology storer from terminal #1132

Open gu4re opened 2 months ago

gu4re commented 2 months ago

Good afternoon,

I am writing here to request some assistance regarding the execution of my application from the terminal. Despite functioning correctly in my working environment (IntelliJ), when generating a build with its corresponding artifact, it fails when attempting to launch OWLOntologyManager.saveOntology(), regardless of the specified format or whether the ontology is being dumped to a file or a stream. Even it fails either using maven for building or IntelliJ Build Artefact options. Attached is the stack trace as well as my code snippet where I am using ontology dumping:

public void exportOntology() {
    Objects.requireNonNull(this.owlOntologyManager);
    Objects.requireNonNull(this.owlOntology);
    try {
        this.owlOntologyManager.saveOntology(this.owlOntology, new RDFXMLDocumentFormat(),
            Files.newOutputStream(Paths.get(URIConstants.ONTOLOGY_URI)));
        log.info("Ontology successfully saved to {}", URIConstants.ONTOLOGY_URI);
    } catch (IOException | OWLOntologyStorageException storageException) {
        log.error("There was an error trying to find/save ontology to {} file", URIConstants.ONTOLOGY_URI);
        log.error("Cause: {}", storageException.getMessage());
        log.error("Exception type: {}", storageException.getClass());
    }
}
// Stacktrace
20:25:54.510 [main] ERROR es.codeurjc.owl.utils.OwlWriter - There was an error trying to print the OWL ontology
20:25:54.510 [main] WARN  es.codeurjc.owl.utils.OwlWriter - Owl ontology malformed!
20:25:54.510 [main] ERROR es.codeurjc.owl.utils.OwlWriter - Cause: Could not find an ontology storer which can handle the format: OWL/XML Syntax
20:25:54.510 [main] ERROR es.codeurjc.owl.manager.OwlManager - There was an error trying to find/save ontology to src/main/resources/schema/ontology.owl file
20:25:54.510 [main] ERROR es.codeurjc.owl.manager.OwlManager - Cause: Could not find an ontology storer which can handle the format: RDF/XML Syntax
20:25:54.510 [main] ERROR es.codeurjc.owl.manager.OwlManager - Exception type: class org.semanticweb.owlapi.model.OWLStorerNotFoundException
org.semanticweb.owlapi.model.OWLStorerNotFoundException: Could not find an ontology storer which can handle the format: RDF/XML Syntax
    at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.saveOntology(OWLOntologyManagerImpl.java:1376)
    at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.saveOntology(OWLOntologyManagerImpl.java:1349)

Please let me know if you need further information or assistance regarding this matter.

Best regards, gu4re.

ignazio1977 commented 2 months ago

Can you add your pom fime?

gu4re commented 2 months ago

Good evening Ignazio,

Here you have my POM file:

<?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>es.codeurjc</groupId>
    <artifactId>sbc-app</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <configuration>
                    <transformers>
                        <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>es.codeurjc.Application</mainClass>
                        </transformer>
                    </transformers>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.apache.jena</groupId>
            <artifactId>apache-jena-libs</artifactId>
            <type>pom</type>
            <version>3.14.0</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.owlapi</groupId>
            <artifactId>owlapi-api</artifactId>
            <version>5.5.0</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.owlapi</groupId>
            <artifactId>owlapi-apibinding</artifactId>
            <version>5.5.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.32</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>2.0.13</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.4.14</version>
        </dependency>
    </dependencies>
</project>
ignazio1977 commented 1 month ago

pom looks correct to me, I've downloaded it in a test project and executed the code, it works when directing the output to a local file.

Check that

Files.newOutputStream(Paths.get(URIConstants.ONTOLOGY_URI))

is working as expected. Another possibility is that the owlapi libraries you downloaded got corrupted during download, so you can try deleting them from your local maven repository and try again.