0

I have a service (subclass of GenericService) that needs to find the path to the deploy directory [under the application server's install directory] at run-time without hard-coding it; that path varies between the many environments in which we work on a daily basis.

I found how do this from within a JSP file, the following gives exactly what I need, but I cannot find a ServeLetContext:

ServletContext context = session.getServletContext();
String path = context.getRealPath("/my/path");

However, I don't have the request or session objects in the service, or do I? I've been looking at

getAdminServlet().getServletConfig().getServletContext().getRealPath("/my/path");

but I'm not getting a context back.

We are using ATG 9.1 on JBoss 4.2.

I appreciate any assistance.

1 Answers1

0

Any service that implements GenericService will also have access to getNucleus() which in turn gives you access to getRealPath(String str).

As I'm not sure why you need to use context.getRealPath(String str) you should note that there are occasions where it may not be best suited for your needs. For example you won't be able to access it if you deploy your application in a .war.

That said, this may be a simpler approach that doesn't care which environment you deploy it to:

private String getBasePath() {
    String basePath = DynamoEnv.getProperty("atg.dynamo.server.home");
    return basePath;
}

It is environment agnostic and since you can't run ATG without a home folder... should work wonders.

Community
  • 1
  • 1
radimpe
  • 3,197
  • 2
  • 27
  • 46
  • radimpe - Thanks for the response. I used getNucleus().getRealPath("xxx"), and the result was (on Windows): "C:\ATG\ATG9.1\home\doc\xxx" and atg.dynamo.server.home returns (on Windows) "C:\ATG\ATG9.1\home". Neither of which will get me to the "deploy" directory, which is under the application server. – account4327 May 30 '13 at 17:34
  • What are you running you ATG instance on? Do you perhaps have a dynamo.env file that incorrectly specify the atg.dynamo.server.home value? Does this property show up in your dynamo.log during startup? I am running WebSphere and double checked that I don't specify it anywhere and it resolves correctly. – radimpe May 30 '13 at 19:22