• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Path to the deployed war class folder

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.............
 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Saloon Keeper
Posts: 28599
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ryan Raina
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
reply
    Bookmark Topic Watch Topic
  • New Topic