2017-02-16 5 views
0

GeoLiteCityファイルにアクセスしようとしていますが、ローカルマシンでは動作していますが、クラウド(Azure)でパスを取得できません。クラウド環境でローカルファイルにアクセス

/src/main/resources/database/GeoLiteCity.dat 

マイコード::コードは、Java WebAppのはTomcat上で実行されているの一部です

void getFile() { 
    if (this.file == null) { 
     try { 
      URL url = this.getClass().getClassLoader().getResource("database/GeoLiteCity.dat"); 
      this.file = new File(url.toURI()); 
      System.out.println(file.getPath().toString()); 

     } catch (Exception ex) { 
      System.out.println(file.getPath().toString(),ex); 
     } 
    } 
} 
+0

どのAzureサービスを使用しましたか? Azure WebAppsまたはクラウドサービス? –

答えて

0

昇天こと ファイルは次のように正確に階層を救いました。私の経験上、this.getClass().getClassLoader().getResource("<the data file path relative to the root classes path>")の方法でリソースを取得したい場合は、のデータファイルwebapps/<your-webapp-name>/WEB-INF/classes/database/の下にあることを確認してください。

WebAppがAzure WebAppにデプロイされている場合は、D:/home/site/wwwroot/webapps/<your-webapp-name>/<the data file path>などのAzure WebApp上の絶対パスのデータファイルを使用して、new File("<the absolute path of data file>")のみを使用することができます。

関連する問題