依赖项的依赖项未包含在内。

8

我有一个Java应用程序,它有一些依赖项,其中包括另一个具有自己依赖关系的项目。每当我从Netbeans运行它或使用mvn exec运行时都很好,但是当我尝试打包它时,即使它已经成功构建,在运行时我会得到以下错误:

Exception in thread "main" org.openrdf.rio.UnsupportedRDFormatException: No parser factory available for RDF format Turtle (mimeTypes=text/turtle, application/x-turtle; ext=ttl)
    at org.openrdf.rio.Rio.createParser(Rio.java:198)
    at org.openrdf.rio.Rio.createParser(Rio.java:213)
    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:104)
    at org.openrdf.repository.base.RepositoryConnectionBase.add(RepositoryConnectionBase.java:217)
    at net.antidot.semantic.rdf.model.impl.sesame.SesameDataSet.loadDataFromFile(SesameDataSet.java:160)

问题在于,芝麻rio解析器似乎没有被包含在内,尽管我可以在我的maven仓库中看到它们。

我已经在所包含的项目中包含了所有依赖项。我还尝试将它们排除,并明确地将它们添加到我的主项目中,但又失败了。

有什么建议吗?

我的依赖树如下:

[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ RMLMapper ---
[INFO] be.ugent.mmlab:RMLMapper:jar:0.1
[INFO] +- junit:junit:jar:4.11:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- xom:xom:jar:1.2.5:compile
[INFO] |  +- xml-apis:xml-apis:jar:1.3.03:compile
[INFO] |  +- xerces:xercesImpl:jar:2.8.0:compile
[INFO] |  \- xalan:xalan:jar:2.7.0:compile
[INFO] +- jlibs:jlibs-xmldog:jar:1.0:compile
[INFO] |  +- jlibs:jlibs-xml:jar:1.0:compile
[INFO] |  |  +- jlibs:jlibs-core:jar:1.0:compile
[INFO] |  |  \- jlibs:jlibs-nbp:jar:1.0:compile
[INFO] |  \- jaxen:jaxen:jar:1.1.1:compile
[INFO] +- com.jayway.jsonpath:json-path:jar:0.8.1:compile
[INFO] |  +- net.minidev:json-smart:jar:1.1.1:compile
[INFO] |  \- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- com.jayway.jsonpath:json-path-assert:jar:0.9.1:test
[INFO] |  \- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] +- net.antidot:db2triples:jar:1.0.2:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.1.2:compile
[INFO] |  +- mysql:mysql-connector-java:jar:5.1.25:compile
[INFO] |  +- postgresql:postgresql:jar:9.1-901.jdbc4:compile
[INFO] |  \- org.slf4j:slf4j-simple:jar:1.6.1:runtime
[INFO] +- org.openrdf.sesame:sesame-runtime:jar:2.7.12:compile
[INFO] |  +- org.openrdf.sesame:sesame-model:jar:2.7.12:compile
[INFO] |  +- org.openrdf.sesame:sesame-repository-api:jar:2.7.12:compile
[INFO] |  +- org.openrdf.sesame:sesame-repository-manager:jar:2.7.12:compile
[INFO] |  |  +- org.openrdf.sesame:sesame-repository-event:jar:2.7.12:compile
[INFO] |  |  +- org.openrdf.sesame:sesame-sail-memory:jar:2.7.12:compile
[INFO] |  |  +- org.openrdf.sesame:sesame-http-client:jar:2.7.12:compile
[INFO] |  |  |  \- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO] |  |  \- org.openrdf.sesame:sesame-http-protocol:jar:2.7.12:compile
[INFO] |  +- org.openrdf.sesame:sesame-repository-http:jar:2.7.12:compile
[INFO] |  |  +- org.openrdf.sesame:sesame-queryparser-api:jar:2.7.12:compile
[INFO] |  |  \- org.openrdf.sesame:sesame-queryresultio-api:jar:2.7.12:compile
[INFO] |  +- org.openrdf.sesame:sesame-repository-sparql:jar:2.7.12:compile
[INFO] |  |  +- org.openrdf.sesame:sesame-queryparser-sparql:jar:2.7.12:compile
[INFO] |  |  \- org.openrdf.sesame:sesame-queryresultio-sparqlxml:jar:2.7.12:compile
[INFO] |  +- org.openrdf.sesame:sesame-repository-contextaware:jar:2.7.12:compile
[INFO] |  +- org.openrdf.sesame:sesame-repository-sail:jar:2.7.12:compile
[INFO] |  |  \- org.openrdf.sesame:sesame-rio-trig:jar:2.7.12:compile
[INFO] |  +- org.openrdf.sesame:sesame-sail-api:jar:2.7.12:compile
[INFO] |  +- org.openrdf.sesame:sesame-sail-federation:jar:2.7.12:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO] |  +- org.openrdf.sesame:sesame-queryparser-serql:jar:2.7.12:runtime
[INFO] |  +- org.openrdf.sesame:sesame-queryresultio-binary:jar:2.7.12:runtime
[INFO] |  +- org.openrdf.sesame:sesame-queryresultio-sparqljson:jar:2.7.12:runtime
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.2.1:runtime
[INFO] |  +- org.openrdf.sesame:sesame-queryresultio-text:jar:2.7.12:runtime
[INFO] |  |  \- net.sf.opencsv:opencsv:jar:2.0:runtime
[INFO] |  +- org.openrdf.sesame:sesame-repository-dataset:jar:2.7.12:runtime
[INFO] |  +- org.openrdf.sesame:sesame-rio-languages:jar:2.7.12:runtime
[INFO] |  +- org.openrdf.sesame:sesame-rio-binary:jar:2.7.12:runtime
[INFO] |  +- org.openrdf.sesame:sesame-rio-nquads:jar:2.7.12:runtime
[INFO] |  +- org.openrdf.sesame:sesame-rio-n3:jar:2.7.12:runtime
[INFO] |  +- org.openrdf.sesame:sesame-rio-rdfjson:jar:2.7.12:runtime
[INFO] |  +- org.openrdf.sesame:sesame-rio-rdfxml:jar:2.7.12:runtime
[INFO] |  +- org.openrdf.sesame:sesame-rio-trix:jar:2.7.12:runtime
[INFO] |  \- org.openrdf.sesame:sesame-sail-rdbms:jar:2.7.12:runtime
[INFO] |     \- commons-dbcp:commons-dbcp:jar:1.3:runtime
[INFO] |        \- commons-pool:commons-pool:jar:1.5.4:runtime
[INFO] +- org.openrdf.sesame:sesame-sail-nativerdf:jar:2.7.12:compile
[INFO] |  +- org.openrdf.sesame:sesame-sail-inferencer:jar:2.7.12:compile
[INFO] |  +- org.openrdf.sesame:sesame-queryalgebra-evaluation:jar:2.7.12:compile
[INFO] |  +- org.openrdf.sesame:sesame-queryalgebra-model:jar:2.7.12:compile
[INFO] |  +- org.openrdf.sesame:sesame-query:jar:2.7.12:compile
[INFO] |  \- org.openrdf.sesame:sesame-util:jar:2.7.12:compile
[INFO] +- com.sun.org.apache:jaxp-ri:jar:1.4:compile
[INFO] |  \- javax.xml.parsers:jaxp-api:jar:1.4:compile
[INFO] +- net.sourceforge.javacsv:javacsv:jar:2.0:compile
[INFO] +- commons-io:commons-io:jar:1.3.2:compile
[INFO] +- net.sf.saxon:Saxon-HE:jar:compressed:9.5.1-4:compile
[INFO] +- org.jodd:jodd-lagarto:jar:3.5:compile
[INFO] |  +- org.jodd:jodd-log:jar:3.5:compile
[INFO] |  \- org.jodd:jodd-core:jar:3.5:compile
[INFO] +- org.jsoup:jsoup:jar:1.7.3:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.2.2:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.2.2:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.6:compile
[INFO] +- com.github.fge:uri-template:jar:0.9:compile
[INFO] |  +- com.github.fge:msg-simple:jar:1.1:compile
[INFO] |  |  \- com.github.fge:btf:jar:1.2:compile
[INFO] |  +- com.google.guava:guava:jar:16.0.1:compile
[INFO] |  \- com.google.code.findbugs:jsr305:jar:2.0.1:compile
[INFO] +- org.openrdf.sesame:sesame-rio-api:jar:2.7.12:compile
[INFO] +- org.openrdf.sesame:sesame-rio-datatypes:jar:2.7.12:compile
[INFO] +- org.openrdf.sesame:sesame-rio-turtle:jar:2.7.12:compile
[INFO] +- org.openrdf.sesame:sesame-rio-ntriples:jar:2.7.12:compile
[INFO] +- org.openrdf.sesame:sesame-rio-n3:pom:2.7.12:compile
[INFO] +- org.openrdf.sesame:sesame-rio:pom:2.7.12:compile
[INFO] \- commons-cli:commons-cli:jar:1.2:compile

也许那个缺失的工厂是一个可选依赖项,并且在具有运行时范围的某个依赖项中找到:org.openrdf.sesame:sesame-queryparser-serql:jar:2.7.12:runtime - 通常IDE不会太区分要添加哪些JAR文件到类路径中,他们只是添加所有的以确保安全。那个工厂在哪个JAR文件中?并且那个JAR文件是否已部署? - wemu
你如何打包?你是否保留原始的JAR文件?我问这个问题是因为Sesame使用SPI和ServiceLoaders来解析,这需要在JAR文件中存在某些元数据。 - Jeen Broekstra
我正在使用maven-assembly插件和jar-with-dependencies,如果这回答了你的问题Wemu。 我没有特别做什么来更改jars。我只是在我的pom文件中包含插件。 我在我的jar文件中看到以下内容,因此我认为依赖项已经(很好地)包含在内:org/openrdf/rio/turtle/ org/openrdf/rio/turtle/TurtleParser.class org/openrdf/rio/turtle/TurtleParserFactory.class .... INF/maven/org.openrdf.sesame/sesame-rio-turtle/ INF/maven/org.openrdf.sesame/sesame-rio-turtle/pom.xml INF/maven/org.openrdf.sesame/sesame-rio-turtle/pom.properties - user3732870
你尝试过联系这个特定库的开发者吗?也许他们可以帮助你了解库的结构以及如何包含它。 - Ruben Verborgh
2个回答

10

从您的考虑出发,我找到了一个构建包括Sesame的应用程序fat-jar的解决方案。我不得不使用另一个Maven插件shade,并且我的构建配置如下:

<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <mainClass>my.package.main.MyMain</mainClass>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
          </transformers>
          <filters>
            <filter>
              <artifact>*:*</artifact>
              <excludes>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.RSA</exclude>
              </excludes>
            </filter>
          </filters>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>
</build>

最有趣的部分包括:

希望对您有所帮助。 祝好, Riccardo


2
它对我也非常有效,非常感谢分享解决方案! - user3732870
我刚刚注意到你已经找到了这个解决方案,在我意识到之前,我更新了自己的答案。+1 给你,因为你先到达了那里(并展示了实际所需的配置)。 - Jeen Broekstra

3
问题在于您错误地重新打包了Sesame jars。 Maven的jar-with-dependencies目标会解压第三方jars并将其内容放入单个大型项目jar中。这对Sesame库不起作用 - 您需要保留原始jars并确保META-INF/services/目录存在。 更新:使用Maven Shade插件而不是使用'jar-with-dependencies'生成onejar,该插件具有特定配置选项以正确处理合并META-INF/services目录。

为什么这个在芝麻上不起作用,也就是说,它有什么不同之处? - Ruben Verborgh
另外,您是否知道如何在不重新打包的情况下完成此操作?那么,是否有可能为使用Sesame的项目创建单个jar文件?是否应手动添加“META-INF / services /”文件夹? - Ruben Verborgh
2
这不是针对芝麻特定的问题 - JAR 重打包对于任何使用 SPI/ServiceLoader 功能的 Java 库都无法正常工作。问题在于,SPI 服务注册是通过 META-INF/services 文件夹中的文本文件进行的,并且当重新打包时会丢失这些文本文件。由于不同的 JAR 包含具有完全相同名称的文件,因此手动修复可能是可行的,但并不容易,因为您不能只是复制这些文件。相反,您需要合并它们的内容。 - Jeen Broekstra
1
在Sesame git存储库中,有一个ant脚本用于在创建Sesame onejar构件时执行此合并操作。我想你可以借鉴它来为自己的项目创建类似的脚本。 - Jeen Broekstra
嗨,我遇到了同样的问题,你有找到解决办法吗? - riccardo.tasso

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接