2016-12-01 15 views
3

HTTPRepositoryにはリポジトリのURLで初期化されています。私はRepositoryConnectionを使って、天気予報のデータを取り出し、リポジトリに追加します。データはWebサービスから取得され、RDFステートメントに変換されてリポジトリに追加されます。これは、スタンドアロンアプリケーションによって定期的に行われます。RDF4J RIO UnsupportedRDFormatExceptionスタンドアロンアプリケーションを使用してHTTPRepositoryにデータを追加するとき

このアプリケーションをIntelliJで実行すると、すべて正常に動作します。

このアプリケーションをサーバー上で実行するには、すべての依存関係を含むjarファイルを作成しました。アプリケーションは、期待どおりに起動し、のデータをリポジトリから取得できます。

アプリケーション私はUnsupportedRDFormatExceptionを取得リポジトリにライトにデータをしようとしたときただし、:

org.eclipse.rdf4j.rio.UnsupportedRDFormatException: Did not recognise RDF format object BinaryRDF (mimeTypes=application/x-binary-rdf; ext=brf) 
    at org.eclipse.rdf4j.rio.Rio.lambda$unsupportedFormat$0(Rio.java:568) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at java.util.Optional.orElseThrow(Optional.java:290) ~[na:1.8.0_111] 
    at org.eclipse.rdf4j.rio.Rio.createWriter(Rio.java:134) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at org.eclipse.rdf4j.rio.Rio.write(Rio.java:371) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at org.eclipse.rdf4j.rio.Rio.write(Rio.java:324) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at org.eclipse.rdf4j.repository.http.HTTPRepositoryConnection.addModel(HTTPRepositoryConnection.java:588) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at org.eclipse.rdf4j.repository.http.HTTPRepositoryConnection.flushTransactionState(HTTPRepositoryConnection.java:662) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at org.eclipse.rdf4j.repository.http.HTTPRepositoryConnection.commit(HTTPRepositoryConnection.java:326) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at org.eclipse.rdf4j.repository.base.AbstractRepositoryConnection.conditionalCommit(AbstractRepositoryConnection.java:366) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at org.eclipse.rdf4j.repository.base.AbstractRepositoryConnection.add(AbstractRepositoryConnection.java:431) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at nl.wur.fbr.data.weather.WeatherApp.retrieveData(WeatherApp.java:122) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at nl.wur.fbr.data.weather.WeatherData$WeatherTask.run(WeatherData.java:105) [weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na] 
    at java.util.TimerThread.mainLoop(Timer.java:555) [na:1.8.0_111] 
    at java.util.TimerThread.run(Timer.java:505) [na:1.8.0_111] 

エラーが発生したソースコードである:

public void retrieveData(){ 
     logger.info("Retrieving data for weather for app: "+ID+" "); 
     RepositoryConnection connection = null; 
     ValueFactory vf = SimpleValueFactory.getInstance(); 
     try { 
      connection = repository.getConnection(); 

      // Retrieving the locations from the repository (no problem here). 
      List<Location> locations = this.retrieveLocations(connection); 
      List<Statement> statements = new ArrayList<>(); 

      // Retrieving weather data from each location and transforming it to statements. 
      for(Location location : locations){ 
       List<Weather> retrievedWeather = weatherService.retrieveWeatherData(location.name,location.latitude,location.longitude); 
       for(Weather weather : retrievedWeather){ 
        BNode phenomenon = vf.createBNode(); 
        statements.add(vf.createStatement(location.ID,WEATHER.HAS_WEATHER,phenomenon,rdfStoreGraph)); 
        statements.addAll(weather.getStatements(phenomenon,vf,rdfStoreGraph)); 
        statements = this.correctOMIRIs(statements,vf); 
       } 
      } 

      // Adding data retrieved from the weather API 
      // This is where the exception happens. 
      connection.add(statements,rdfStoreGraph); 

     } catch (Exception e) { 
      logger.error("Could not retrievedata for weather app: '"+ID+"' because no monitor locations could be found.",e); 
     } finally { 
      if(connection != null){ 
       connection.close(); 
      } 
     } 
    } 

HTTPRespositoryであります

 repository = new HTTPRepository(rdfStore.toString()); 
     ((HTTPRepository)repository).setPreferredRDFFormat(RDFFormat.BINARY); 
     ((HTTPRepository)repository).setPreferredTupleQueryResultFormat(TupleQueryResultFormat.BINARY); 

フォーマットをTURTLEに変更しようとしました。しかし、それは違いはありません。

これを解決する方法を教えてもらえますか?

NB。 RDF4Jサーバーとライブラリの両方にバージョン2.0.1(rdf4j)があります。

答えて

4

このアプリケーションをサーバー上で実行するには、すべての依存関係を含むjarファイルを作成しました。

「fat jar」を作成し、おそらくSPIレジストリファイルを適切にマージしていないという問題があります。

RDF4JのRioパーサー(および他のいくつかのモジュールも同様)は、JavaのService Provider Interface(SPI)メカニズムを使用して自身を登録します。このメカニズムは、各パーサー実装の完全修飾名を含むjarファイルのMETA-INF\servicesのテキストファイルに依存しています。

jarをマージすると問題が発生します。各Rioパーサーjarには同じ名前のレジストリファイルがありますが、内容は異なります。 fatのjarファイルを作成するためにmavenアセンブリプラグインのようなものを使用している場合、各レジストリファイルは次のファイルによって上書きされます。結局、RDF4Jは最後に、レジストリ・ファイルが最後にファット・ジャーに追加されたパーサーしか見つけられません。

解決策は、fat jarファイルをまったく作成しないか、必要な場合は、レジストリファイルを上書きするのではなく、別の手法を使用してマージします。 maven shade pluginには、このための良い設定オプションがあります:ServicesResourceTransformer

+1

私は別の方法をとることにして、「痩せた」瓶を作り、依存関係を別のディレクトリ 'lib'に出力しました。すべての依存関係を含むクラスパスがマニフェストに含まれています([この質問]のように)(http://stackoverflow.com/questions/8325819/how-can-i-create-an-executable-jar-without-dependencies-using- maven))。ありがとう! –

関連する問題