• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

weblogic using external properties file

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am deploying my applications on to weblogic 12.1.1 server. I have coded in such a way that my applications write the logs in /home/appname/logs folder in the weblogic server. This set up is in DEV instance. Now we are moving to QA and UAT and our weblogic admin says not to put anything in the /home directory and he gives a different location for QA and another location for prod. so for each environment I end up modifying the code to point to the specific location. IS there any possibility to handle this by keeping a external system.properties file and having the same war file for all the environments. Please help me to accomplish this.

Thanks
 
Ranch Hand
Posts: 376
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you can do that.
One way to do it is using Spring: property-placeholder
 
usha kannan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you explain me in little more detail . I am new to spring too. I need a property file specific to each weblogic environment(dev, qa,uat and prod) and I want to deploy the same war file in all the environments. If any property changes I just go and update the property file .where in weblogic server do I place my property file .How to accomplish this.
 
German Gonzalez-Morris
Ranch Hand
Posts: 376
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Googling you can find several examples, such us:

http://www.mkyong.com/spring/spring-propertyplaceholderconfigurer-example/

more details in that feature:
http://www.baeldung.com/2012/02/06/properties-with-spring/

 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The mkyong example still requires a custom WAR build for each target machine, just swapping out the properties file within the WAR.

My WARs are all built to run unmodified on development, test, and production machines.

They do this by getting their server-specific information from outside sources which are usually property files located in a location external to both WARS and the server itself (in Linux, that usually means I have a /var/lib/mywebapp directory to hold it). To avoid coding server-specific file paths in the Spring configuration, I define the config path as a WAR environment property and use JNDI to retrieve it. The server-specific information is defined in the server-specific deployment descriptor data. For Tomcat, that would be the Context definition. I don't remember what the WebLogic equivalent is. If you don't provide an external path override in the server-specific deployment data, the default environment value is the one defined in the WAR.
 
German Gonzalez-Morris
Ranch Hand
Posts: 376
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the value for PropertyPlaceholderConfigurer can be classpath or filesystem

i.e.:





http://forum.spring.io/forum/spring-projects/container/36639-path-of-property-file-in-propertyplaceholderconfigurer
 
usha kannan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you both for your valuable input. I still have a question.

If I go for Spring:PropertyPlaceholderConfigurer you say I do not want to go for a custom WAR build for each target machine. If that is the case where in weblogic server do I go and modify the properties.

Thanks
 
German Gonzalez-Morris
Ranch Hand
Posts: 376
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's right, you won't need to change your war file, only the local properties file in each environment.
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Per-server data is assigned via targets and deployment plans. If you're using an external properties file (as I recommend), then the deployment plan would be the place to define where the properties file is. Or, if the list of properties is short, you could define them as deployment plan variables. In your example, rather than pointing to a specific file, you'd probably want to point to a directory containing those files.

That should allow Spring constructs something like this:


 
usha kannan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly I tried the approach what Morris suggested. I added the below code in my applicationContext.xml

<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:system.properties</value>
</list>
</property>
</bean>


Next I created a system.properties file under src/main/resources folder and defined

log.path = C:/Oracle/Middleware/Oracle_Home/user_projects/domains/ABCD/logs

Next I gave the path in my log4j.xml as below

<log4j:configuration>
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="$(log.path)/app.log" />
<param name="Threshold" value="DEBUG" />


Next I created a war file and deployed in my local weblogic server but the log file app.log did not get created in the specified location. Am I missing something. Please advise.

Thanks
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You said $(log.path). Are you sure that wasn't supposed to be ${log.path}?
 
usha kannan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, you are right Tim. Thanks for pointing out that. I changed it to ${log.path} ,but still not getting the file generated in the specified location. :-(

<param name="File" value="${log.path}/app.log" />
 
German Gonzalez-Morris
Ranch Hand
Posts: 376
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a different issue. Please, try first with a literal value and not using ${log.path} variable.

if that works then try using that variable, and let's try to fix that issue.
 
usha kannan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Morris, as you suggested I tried using the literal value and that worked.


<log4j:configuration>
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/Oracle/Middleware/Oracle_Home/user_projects/domains/ABCD/logs/app.log" />
<param name="Threshold" value="DEBUG" />
 
German Gonzalez-Morris
Ranch Hand
Posts: 376
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good !

Now, the ${log.path} is actually a system property that must be in jvm:

i.e.:



In this case in Weblogic script when starting up, and not an environment variable.

 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That won't work either. To define a system property, it would be "-Dlog.path=..."

But system properties are a very bad place to put webapp parameters. You really should define them in the deployment plan.
 
German Gonzalez-Morris
Ranch Hand
Posts: 376
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:That won't work either. To define a system property, it would be "-Dlog.path=..."

But system properties are a very bad place to put webapp parameters. You really should define them in the deployment plan.



Not necessarily, it will work in both ways:



Test.java


output:


It can be modified in java arguments thru admin console.
 
usha kannan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added -Dlog.path=C:/Oracle/Middleware/Oracle_Home/user_projects/domains/ABCD/logs in java arguments thru admin console and still did not work
 
German Gonzalez-Morris
Ranch Hand
Posts: 376
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you restart the servers ?
(probably you are using nodemanager)
 
usha kannan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes I did restart the server.
 
usha kannan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please confirm if the format of the path given in system.properties file is correct. (is it forward slashes??

log.path = C:/Oracle/Middleware/Oracle_Home/user_projects/domains/ABCD/logs


Also where exactly in setDomainEnv.cmd file do I add

-Dlog.path=C:/Oracle/Middleware/Oracle_Home/user_projects/domains/ABCD/logs


I am deploying my application on to the admin server in my local.


Thanks
 
German Gonzalez-Morris
Ranch Hand
Posts: 376
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, those properties look correct.

You can try a simple Java class (maybe a simple Servlet) to retrieve that property :



give it a try.
 
usha kannan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.

The value is coming as
"=null"
 
usha kannan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved this issue using log4j 2 which has lookups that pulls the values from system property.

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="warn">
<appenders>
<RollingFile name="MyRollingFile" fileName="${sys:Log4j.Log.Dir}/myApp.log" filePattern="${sys:Log4j.Log.Dir}/myApp-%i.log">
<PatternLayout>
<pattern>%highlight{%d{COMPACT}|%-5p|%c{1}|%m%n}</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="5MB" />
</Policies>
<DefaultRolloverStrategy max="5" />
</RollingFile>
</appenders>
<loggers>
<root level="debug">
<AppenderRef ref="MyRollingFile" />
</root>
</loggers>
</configuration>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic