Question

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.

No correct solution

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top