java - Getting the absolute path of a file within a JAR within an EAR? -
I have a J2EE app that is positioned as an EAR file, which in turn replaces a JAR file for the business layer code EJB's) and a war file for the web layer code. The ER file has been deployed in JB 3.2.5, which opens EAR and war files, but there is no Jar file (this is not a problem, it is just FYI).
A file file inside the jar is a MS Word template whose full path is required to pass some basic MS Word code (using FWIW).
The problem is that if I try to get the file like this (from within some code) in the JAR file):
url = getClass ( ). GetResource ("myTemplate.dot"); File file = new file (url.toURI ()); // & lt; = Fails! String full path = file.getAbsolutePath (); // Open MS Word to full path to open as a document ... then java.io.file constructor allows illegal virtualization Fly "URI is not hierarchical". Both URLs are similar to string () output, that is:
jar: file: / g: /jboss/myapp/jboss/server/default/tmp/deploy/tmp29269myapp.ear -contents / Myapp.jar! /my/package/myTemplate.dot This is valid on many paths file systems, but the rest (not internal to the JAR file)):
< Code> G: /jboss/myapp/jboss/server/default/tmp/deploy/tmp29269myapp.ear-contents
What is the easiest way to get the full path of this file
My current solution is in the temporary directory of the file, then use the full path of the copy:
file tempDir = new file (System.getProp Erty ("java.io.tmpdir")); File temporary file = new file (tempDir, "templateCopy.dot"); InputStream templatestream = getClass (). GetResourceAsStream ("myTemplate.dot"); IOUtils.copy (templatestream, new fileoptputstream (temporary file)); String full path = temporary file.gate absolit path (); I prefer a solution that does not contain a copy of the file.
Comments
Post a Comment