2

When I try to use Sesame Rio in a standalone Java application packaged with the maven-shade-plugin, I get

Exception in thread "main" org.openrdf.rio.UnsupportedRDFormatException: Did not recognise RDF format object N-Triples (mimeTypes=application/n-triples, text/plain; ext=nt)
    at org.openrdf.rio.Rio.lambda$unsupportedFormat$0(Rio.java:630)
    at org.openrdf.rio.Rio$$Lambda$1/736709391.get(Unknown Source)
    at java.util.Optional.orElseThrow(Optional.java:290)
    at org.openrdf.rio.Rio.createParser(Rio.java:119)
    at org.openrdf.rio.Rio.createParser(Rio.java:137)
    at org.openrdf.repository.util.RDFLoader.loadInputStreamOrReader(RDFLoader.java:318)
    at org.openrdf.repository.util.RDFLoader.load(RDFLoader.java:222)
    at org.openrdf.repository.util.RDFLoader.load(RDFLoader.java:105)
    at org.openrdf.repository.base.AbstractRepositoryConnection.add(AbstractRepositoryConnection.java:255)

Running the application from Eclipse succeeds. How can I fix this?

thSoft
  • 21,755
  • 5
  • 88
  • 103

1 Answers1

2

The RDF format handlers in Rio are implemented as services, so the service descriptors have to be included in the shaded JAR. This is achieved with the ServicesResourceTransformer:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.2</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>

More info:

thSoft
  • 21,755
  • 5
  • 88
  • 103