Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How To: Path of JBoss Server deployment folder !

 
Prathamesh Gaddam
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Using java.io.File I want to retreive (FileRetriever.java) the specific files, from JBoss Server deployment folder. For example, following are the paths of deployed project. Using FileRetriever.java I want to get the fles from the directory ..\layout\templates\.

Please suggest how can I do this dynamically i.e the FileRetriever.java should get the folder path (\layout\templates) depending on its (FileRetriever.java or FileRetriever.class) location. It needs to be irrespective of location of JBoss Server Installation. Is there any altenative using web.xml or component.xml files.

Thank you in advance !

PATHS:

- JBossServerPath: e:\jboss-4.2.1.GA\

- IntendedDirectoryPath: e:\jboss-4.2.1.GA\server\default\deploy\my.war\layout\templates

- FileRetriever.class (.class file which retrives files from templates directory) Path:
E:\jboss-4.2.1.GA\server\default\deploy\my.war\WEB-INF\dev\org\domain\my\session

- FileRetriever.java path:
E:\jboss-4.2.1.GA\server\default\deploy\my.war\WEB-INF\classes\org\domain\myl\session
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See these JBoss system properties which you can access by a call to System.getProperty(...)
 
Prathamesh Gaddam
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply.

I tried to test, using JBoss properties, the path of JBoss server installation as:

. Is it the right way? Please guide further.

However, the value is printed as null. (I need the location of WEB-INF folder from the JBoss server).

Note: I m using the JBoss server vide Eclipse IDE with Seam Framework.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Close:

System.out.println("JBoss Home: "+System.getProperty("jboss.home.url"));

On the page Jaikiran cited, the bulleted text is the the system property name, the text in the light background is the default value.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess I should have read your post a little further. To access your WEB-INF folder, I suggest placing a properties file at WEB-INF/classes, and then in your servlet doing:

URL url = Thread.currentThread().getContextClassloader().findResource("xxx.properties");

The url will be the full path to the properties file, from there you should be able to find the full path for the WEB-INF directory.
 
Prathamesh Gaddam
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Peter !

The workout



gave the value as

file:/E:/MyWorkspace/UI/build/classes/components.properties

However the path where my xxxx.template.xhtml files deployed, are at

E:\Softwares\jboss-4.2.1.GA\server\default\deploy\UI.war\layout in templates folder.

I need the path so that my FileRetriever.java can dynamically load the list of xxxx.templates.xhtml, irrepective of location of JBOss server installed.

Is there any other way such as registering the path in any of the web.xml, seam.xml or jboss.xml?

I'm a newbie unaware of the relation between URL and actual directory path, and how they are used. Please guide me towards the first messagse of this post.
 
Roshan Qureshi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prathmesh,

You can use following code in any jsp or servlet.

String serverPath= getServletContext().getRealPath("/");
This will give you full path of the server from root directory to your web application directory.
For me its: " D:\local\tomcat-6.0.29\webapps\myapp " when I sys out from myapp application.

Once you got the whole real path for the server system as above you can get the path relative to your directory.
So if I have some data file in myapp\data - I can get it appending \data\filename to the serverPath which we got earlier.
This will work in all situation even you have multiple servers installed on the same system.

Hope this will work for you.
Regards,
Roshan Qureshi
CYGNEX Technologies
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic