I want to know how can I get the path to the classes folder inside a war using java...
path I want to get is should be C:\jboss-5.1.0.GA\jboss-5.1.0.GA\server\default\deploy\abc.war\WEB-INF\classes
is this one approach..String tempPath = getClass().getResource("/").getPath();
Thanks in advance.............
You cannot do that without violating the J2EE standard.
According to the spec, a WAR is a JAR-format archive file. Note the word "file", not "directory", not "files". In a WAR file, the WEB-INF/classes "directory" is just a path within the WAR and cannot be accessed natively by the host OS filesystems.
Within a WAR, you can obtain access by using the HttpServletRequest getResource() and getResourceAsStream() methods. They don't return filesystem paths, but they do return objects that the webapp can use to read WAR resources such as property files.
Some webapp servers support the concept of optionally "exploding" a WAR. In that case, the WAR is unzipped, and there will be a physical WEB-INF/classes directory on the filesystem. However, exploded WARs are not part of the J2EE standard and any webapp that depends on a WAR having been exploded will not be standards-compliant.
Under absolutely NO circumstances should you ever WRITE to a location within a WAR. Even if the server permits it, you WILL experience pain.
Bjoke: A "Bully Joke". A Statement or action made with malicious intent - unless challenged. At which point it magically transforms into "I was just funnin'" or "What's the matter, can't take a joke?"
thanks all for replies..
I am doing is a url deployment...My app server is Jboss5.1.0 ga...I have edited profile.xml and i have given the url to the deployed artifact.....war is generated by the installer while installing the product on the customer side......It's already in exploded form ......That's the reason I wanted to know about this....