Do not extract the absolute resource path

advertisements

I have a template file under /src/main/resources and i want to get the absolute path of it, the problem is that I'm getting a relative path and not a absolute path.

I need to get the absolute path of the file in my computer after loading the template inside the project. What I'm doing now is this:

URL location = this.getClass().getResource("/template/template2.vm");
String fullPath = location.getPath();

This returns: (java.lang.String) vfs:/content/MyProyect-1.0.0-SNAPSHOT.war/WEB-INF/classes/templates/template2.vm

If you do it in Eclipse it gives the full path, but deploying in Netbeans and without an IDE returns this result. I'm using jboss for deploying.

I've also tried doing

String fullPath = location.getAbsolutePath();

and i keep getting this result.


Is this always going to be local? If so can you do this:

URL location = this.getClass().getResource(/template/template2.vm);
File f = new File(location.toUri());
String fullPath = f.getAbsolutePath();