How to dynamically pass parameters to web.xml using weblogic 10.3.x?

I am trying to pass a JVM parameter for a variable configured in web.xml as a context parameter using the -D notation when starting the weblogic server. I have already tried the same configuration using Tomcat 7, and it works as expected, but it does NOT work on the weblogic 10.3.3 server. Any clues?

web.xml

<?xml version="1.0" encoding="UTF-8" ?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>testeParWebXml</display-name> <context-param> <description>Habilita ou desabilita a configuração de debug do Facelets! Página de debug do Seam.</description> <param-name>facelets.DEVELOPMENT</param-name> <param-value>${habilitar.debug}</param-value> </context-param> <welcome-file-list> 

Then when starting jvm I pass the parameter using:

 -Dhabilitar.debug=true 

And I built Servlet for testing:

 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter pw = response.getWriter(); String valorParametro = getServletContext().getInitParameter("facelets.DEVELOPMENT"); pw.write("Param value from web.xml ==>> " + valorParametro); } 

As I said, using Tomcat, if I change the value to false or true on the -Debar.debug flags, it correctly prints the value in the servlet.

 Param value from web.xml ==>> true 

In weblogic, I get output like:

 Param value from web.xml ==>> ${habilitar.debug} 

As weblogic noted, it does NOT analyze the value of the variable specified in web.xml.

Is it possible to make this work properly in weblogic 10.3.3?

+6
source share
2 answers

It appears that there is no consistent behavior across different containers. IMHO, you should not do this. I always used (and always saw how people use) web.xml, which contains default values ​​(not parameterized values) for things. Please check out these additional resources (including some not-so-elegant but working approaches to your problem):

+3
source

First attempt: I believe that filtering important files such as web.xml is not good practice. However, you can use ant or maven to do this.

===

Second attempt: Ok If identical packages are required, I would prefer to change the doPost method . Instead of passing a value there, it can be passed a key and set using the System.getProperty method. And also a default value, such as a development environment, makes sense.

0
source

Source: https://habr.com/ru/post/900133/


All Articles