简体   繁体   中英

classloader.getResource return a path with war file

I can't understand the behavior of this line on my computer :

File versionFile = new File(classLoader.getResource("Version.txt").getFile());

In face the classLoader.getResource("Version.txt").getFile() return a path like :

C:****\ServiceManager\target\ServiceManager.war!\WEB-INF\classes\Version.txt

It seems java generate a path inside my war file and it doesn't works. However my colleague with the exact same code have a normal path inside our output folder.

Does someone have an idea?

Thanks

I found the root cause of this issue, it was a project configuration issue.

In webshpere liberty server, if you have dependencies with several projects, you have to go in properties project > Deployment assembly > and add your projects. After that, the server will generate a myProject.war.xml which contains different node. Some node have targetInArchive attribute with a path and this configuration force the classloader to return a path inside de generated war.

Hope these informations will help someone.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM