this.getClass().getResource("").getFile() returning path with "file:" at the beginning when running project with IntelliJ/Jetty 8.1.14

StackOverflow https://stackoverflow.com/questions/23367158

سؤال

I am trying to switch my dev environment from Eclipse to IntelliJ. I am developing a Java EE application that uses the path returned from this.getClass().getResource("").getFile() to create a new FileInputStream. When running the project with Eclipse/Jetty (from the Jetty plugin on the Eclipse marketplace) and on production with Glassfish, the string returned looks like "/C:/path/to/class/in/jar/".

However, when running the project with IntelliJ/Jetty (8.* from http://download.eclipse.org/jetty/stable-8/dist/) the file path returned looks like "file:/C:/path/to/class/in/jar/". The 'file:' at the beginning of the string is causing a FileNotFoundException on "new FileInputStream(path)".

I am developing on Windows 8.

I can easily strip the "file:" from the string, but I would rather not change the codebase to fix what appears to be an environment issue. Is there something I can do so that getFile() does not return a path starting with "file:"?

هل كانت مفيدة؟

المحلول

Figured it out. The application was deploying one of the subprojects to a jar file instead of a folder. This was causing URL#getFile() to append the "file:" protocol for some reason. To solve this I went to Module Settings > Artifacts > 'exploded' module and moved the subproject's compile output from the jar file to a folder.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top