Hi,
Try this one :
MessageContext mc = MessageContext.getCurrentMessageContext();
mc.getConfigurationContext().getRealPath("/");
if you just need this information at the instanciation of your service, you can
find the information directly in the ServletContext parameter of your init
method :
public void init(ServiceContext sc) throws Exception{
System.out.println(sc.getRootContext().getRealPath("/"));
}
Tony.
> Date: Mon, 11 Jul 2011 11:16:27 -0700
> From: [email protected]
> To: [email protected]
> Subject: How to get the directory path in the service implementation code
>
> Hi, devs:
>
> I implemented a axis2 service and deployed it to tomcat. My tomcat
> webapps is configured as /var/www/webapps. So the axis context has this
> file structure:
>
> /var/www/webapps/axis2/axis2-web
> /var/www/webapps/axis2/META-INF
> /var/www/webapps/axis2/WEB-INF
>
> In my service implementation, it has code to generate a new directory
> /var/www/webapps/axis2/mydata and use it to write, read and delete files.
>
> In order to archive this purpose, I set an environment variable
> AXSI_HOME= /var/www/webapps/ which let the implementation code aware
> where the service was deployed. It works fine. But this introduce a
> extra step in installation, set up an environment variable.
>
> Now I have got a new task to create a installer for this web service.
> Ideally I want to create a war file and the installation just needs a
> user dropping the war file into the tomcat webapps directory. There are
> no any environment variable setting or script running.
>
> In order to do this, I want to the implementation code itself can detect
> where it was deployed.
>
> I added the following code in my implemenation:
>
> MessageContext messageContext = MessageContext.getCurrentMessageContext();
> if(messageContext != null) {
> ConfigurationContext configurationContext =
> messageContext.getConfigurationContext();
> if(configurationContext != null){
> System.out.println("context root
> "+configurationContext.getContextRoot());
> System.out.println("servcie context path
> "+configurationContext.getServiceContextPath());
> System.out.println("servcie path
> "+configurationContext.getServicePath());
> }
> }
>
> The output is:
> context root /axis2
> servcie context path /axis2/services
> servcie path services
>
> Those are NOT what I want. I want something which can get
> /var/www/webapps/axis2. Do you have any idea? Any suggestion and
> comment will be highly appreciated.
>
>
> Regards,
>
> Jing
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>