2014-06-30 121 views
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) 

所以問題是,芝麻里約解析器似乎不被包含,即使我可以在我的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 
+0

也許這缺少的工廠是一個可選的依賴,並在具有範圍運行時依賴的一個發現:org.openrdf.sesame:芝麻的QueryParser-serql:罐子:2.7.12:運行時間 - 通常IDE的不要區分那些添加到classpath的jar文件 - 他們只是將它們全部添加到安全的地方。那個工廠在哪個罐子裏?這是部署中的jar嗎? – wemu

+0

你如何包裝?你保留原來的罐子嗎?我要問的原因是Sesame使用SPI和ServiceLoaders作爲解析器,它需要某些元數據存在於jar中。 –

+0

如果回答您的問題Wemu,我正在使用maven-assembly插件和jar-with-dependencies。 我沒有做任何特別的改變罐子。我只是在我的pom文件中包含插件。 我在我的jar文件中看到以下內容,所以我認爲依賴項包含在內(well): org/openrdf/rio/turtle/ org/openrdf/rio/turtle/TurtleParser。類 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

回答

10

從您的考慮開始我發現了一個解決方案,用於構建包括芝麻在內的應用程序的一個fat-jar。我不得不使用其他的Maven插件,它是遮陽和我構建的配置如下:

<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> 

最有趣的部分是:

希望它能幫助。 乾杯, 裏卡多

+2

它對我來說也很有魅力,非常感謝分享解決方案! – user3732870

+0

我剛剛注意到你已經找到了這個解決方案,在我意識到之前我更新了自己的答案。你的+1首先到達那裏(並顯示需要的實際配置)。 –

3

的問題是,你是不正確的重新包裝瓶芝麻。 Maven的jar-with-dependencies target解包第三方jar將內容放入一個大項目jar。這不適用於芝麻圖書館 - 您需要原始瓶子完好無損,META-INF/services/陳列櫃完好無損。

更新而是生產與「罐子,有依賴性」一onejar的,你可以使用Maven Shade plugin,其中有specific config options處理正確合併META-INF/services目錄。

+0

這是怎麼回事芝麻不起作用,即在哪些方面不同? –

+0

另外,你可能知道如何做到這一點,而不重新打包?那麼是否有可能爲使用芝麻的項目創建一個單獨的jar?應該手動添加'META-INF/services /'文件夾嗎? –

+2

這不是特定於芝麻 - 對於使用SPI/ServiceLoader功能的_any_ java庫,jar重新打包無法正常工作。問題在於SPI服務註冊通過META-INF/services文件夾中的文本文件發生,並且這些文本文件在重新打包時會丟失。由於不同的罐子包含名稱完全相同的文件,手動修復是可能的,但並不容易,因爲您不能複製文件。相反,你需要合併他們的內容。 –