*
The moose likes JBoss/WildFly and the fly likes Path to the deployed war class folder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Path to the deployed war class folder" Watch "Path to the deployed war class folder" New topic
Author

Path to the deployed war class folder

Ryan Raina
Greenhorn

Joined: Jun 16, 2010
Posts: 28
HI everyone
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.............
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

So far this is where you will find your .class files. C:\jboss-5.1.0.GA\jboss-5.1.0.GA\server\default\deploy\abc.war\WEB-INF\classes

Is there any problem? Or do you want to know how to get this path by java commands?


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16020
    
  20

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.

Customer surveys are for companies who didn't pay proper attention to begin with.
Ryan Raina
Greenhorn

Joined: Jun 16, 2010
Posts: 28
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....
 
wood burning stoves
 
subject: Path to the deployed war class folder