[請益] 部署到server後找不到檔案

作者: qazsd ( )   2017-09-04 17:15:56
藉助一下軟體版廣大的人氣,請問板上前輩們
小弟有Maven專案資料夾結構如下:
Project
├src/main/java
│ └ com.abc.xyz
│ └Auth.java
└src/main/resources
└certs
└credential.p12
Auth.java裡有段程式碼用來驗證:
=====================================================================
File file = new File(classLoader.getResource("cert.p12").getFile());
String filePath = file.getAbsolutePath();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(Collections.singleton(
CalendarScopes.CALENDAR_READONLY))
.setServiceAccountPrivateKeyFromP12File(new File(filePath))
.setServiceAccountUser(SERVICE_ACCOUNT_USER)
.build();
=====================================================================
將該專案檔的jar部署到Server上後
會出現找不到credential檔案的錯誤訊息
想請問credential檔案應該放在專案或server哪裡才能被找到?
又該怎麼指定路徑呢?
作者: gpctv (gpctv)   2017-09-04 18:08:00
你有試著印出來看看嗎
作者: alan3100 (BOSS)   2017-09-05 08:20:00
"java read file from jar" 問google
作者: mureka (mureka)   2017-09-15 06:08:00
試試看將p12檔移到src底下,或是resources底下

Links booklink

Contact Us: admin [ a t ] ucptt.com