# 讀取JAR resource文件

此次測試範例專案架構

![SRestapi dependencies S\_Core](https://1934262382-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRmnDr9RXeSmhkUmaUsX7%2Fuploads%2FS6nYsuEgCIPr2T8u0T04%2F%E6%88%AA%E5%9C%96%202022-06-14%20%E4%B8%8A%E5%8D%8810.57.43.png?alt=media\&token=5a463619-e78c-45c6-a6c1-4ad7f14e38be)

## 問題及分析

SRestapi 打包後, 啟動時報錯找不到 `GeoLite2-Country.mmdb` 這個檔案.

```
2022-06-09 15:59:29.944 [main] DEBUG o.s.b.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'fetchGeoLiteDatabaseReader'
java.io.FileNotFoundException: class path resource [GeoLite2-Country.mmdb] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/caster/Documents/workplace/splatform/S_Restapi/build/libs/SPlatform_Restapi.jar!/BOOT-INF/lib/S_Core-0.0.1-SNAPSHOT-plain.jar!/GeoLite2-Country.mmdb
        at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:217)
        at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:162)
        at com.longxiang.config.CommonConfig.fetchGeoLiteDatabaseReader(CommonConfig.java:40)
        at com.longxiang.config.CommonConfig$$EnhancerBySpringCGLIB$$47c48ffc.CGLIB$fetchGeoLiteDatabaseReader$1(<generated>)
        at com.longxiang.config.CommonConfig$$EnhancerBySpringCGLIB$$47c48ffc$$FastClassBySpringCGLIB$$40fa806d.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
```

但是去把SRestapi打包的Jar, 找得到這個檔案但為什麼會讀取不到呢？ 待補詳細原因先附上最後解決方式

![final](https://1934262382-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRmnDr9RXeSmhkUmaUsX7%2Fuploads%2FBAOxiqxCATOqwx8pI1gt%2F%E6%88%AA%E5%9C%96%202022-06-14%20%E4%B8%8A%E5%8D%8811.44.57.png?alt=media\&token=304cf3d4-13dd-434f-a2f4-952d077d9bfe)
