Path of Weblogic domain directory in a Java app
Solution 1
System.getProperty("weblogic.Name")
will return the WebLogic server's name as it is passed via a JVM argument during startup of the server, from the script startWebLogic.sh or startWebLogic.cmd:
%JAVA_HOME%\bin\java %JAVA_VM% %MEM_ARGS% -Dweblogic.Name=%SERVER_NAME% ...
You can add another JVM argument to pass the WebLogic domain, that is available as the environment variable DOMAIN_HOME
:
%JAVA_HOME%\bin\java %JAVA_VM% %MEM_ARGS% -Dweblogic.Name=%SERVER_NAME% -Dweblogic.domainDir=%DOMAIN_HOME%...
which you can then read using
System.getProperty("weblogic.domainDir");
You can also read the environment variable DOMAIN_HOME
directly using System.getenv(String)
:
String domainDir = System.getenv("DOMAIN_HOME");
Solution 2
You can use the JMX service to get hold of the domain home directory from the 'RuntimeService > DomainConfiguration > RootDirectory'. You can use the following code to get hold of the domain directory from within an app.
InitialContext ctx = new InitialContext();
MBeanServer server = (MBeanServer)ctx.lookup("java:comp/env/jmx/runtime");
ObjectName service = new ObjectName("com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
ObjectName domain = (ObjectName)server.getAttribute(service, "DomainConfiguration");
System.out.println(server.getAttribute(domain, "RootDirectory"));
For more information you can refer to http://download.oracle.com/docs/cd/E17904_01/web.1111/e13728/accesswls.htm#JMXCU144
L4zl0w
Software engineer, but not developer. Still fiddling with code in my free time, specifically in PHP and JS.
Updated on July 09, 2022Comments
-
L4zl0w almost 2 years
Is there an easy way of reading the directory path of the Weblogic domain the Java application is running in?
I can easily access the name of the server with System.getProperty("weblogic.Name") but I don't know what is the variable that holds the path of the Weblogic domain folder if there is one at all.
I know I could set up a variable like this but I was wondering if there is one already in Weblogic.
Many thanks