2016-10-05 7 views
0

JSONファイルを別のモジュールの/resourcesディレクトリから現在のモジュールに読み込んでロードし、jacksonを使用してJSONをマップします。別のモジュールからJSONファイルを読み込みまたはロードする

現在のモジュール名は "transform"で、必要なリソースファイルは "schema"という別のモジュールにあります。 「変換」モジュールのpom.xmlファイルにmaven という「スキーマ」を追加しました。

"schema"モジュールで "example.json"という名前のファイルを読み込み/読み込む必要があります。

​​:

は、しかし、私は次のエラーを取得しておきます。

私がこれまで持っているもの:

Map<String, String> map = objectMapper.readValue(
       getClass().getClassLoader().getResourceAsStream("/schema/resources/example.json"), 
               new TypeReference<Map<String, String>>(){}); 

はちょうどexample.jsonへのフルパスが "/schema/resources/example.json" であるとしましょう。

+1

はhttp://stackoverflow.com/questions/5292283/use-a-dependencys-resources](http://stackoverflow.com/questions/5292283/use- [以下のMavenプラグインで試してみますa-dependencys-resources) – Satish

答えて

1
Map<String, String> map = objectMapper.readValue(Thread.currentThread().getContextClassLoader().getResourceAsStream("/schema/resources/example.json"), 
              new TypeReference<Map<String, String>>(){}); 
+0

ありがとう!私はとても似たようなことを試してみました。これは私がしたことです: 'ObjectMapper.readValue(MyClassInDifferentModule.class.getResourceAsStream("/schema/resources/example.json ")、新しいTypeReference >(){}); – dinky

関連する問題