I exported a project that reads 2 configuration files. However, when I execute the jar, it gets this error:
Error: java.io.FileNotFoundException: config/dbConnection.config (No such file or directory)
Error: java.io.FileNotFoundException: config/test.config (No such file or directory)
com.smart.ets.services.ServiceException: com.smart.ets.services.ConfigErrorException
at com.smart.ets.services.TransactionServiceImpl.getConfigData(TransactionServiceImpl.java:30)
at com.smart.ets.controllers.Simulator.getTransactionSimulationResults(Simulator.java:41)
at com.smart.ets.controllers.Simulator.main(Simulator.java:26)
Caused by: com.smart.ets.services.ConfigErrorException
... 3 more
mickey91@mickey-espiritu:~/Documents/Dropbox$ java -jar ETS.jar
Error: java.io.FileNotFoundException: config/dbConnection.config (No such file or directory)
Error: java.io.FileNotFoundException: config/test.config (No such file or directory)
com.smart.ets.services.ServiceException: com.smart.ets.services.ConfigErrorException
at com.smart.ets.services.TransactionServiceImpl.getConfigData(TransactionServiceImpl.java:30)
at com.smart.ets.controllers.Simulator.getTransactionSimulationResults(Simulator.java:41)
at com.smart.ets.controllers.Simulator.main(Simulator.java:26)
Caused by: com.sm
art.ets.services.ConfigErrorException
... 3 more
Any way to fix this? It works if I run the project(not the jar file of the project)
You neglect to mention how you're accessing the files, but from the error it looks like you're trying to access them as files--but they're not, they're resources on the classpath.
As such, you should be using getResourceAsStream . The name of the resource would be the package-relative path.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.