OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.14k stars 587 forks source link

JSF: javax.faces.PROJECT_STAGE set automatically #16133

Closed melloware closed 3 years ago

melloware commented 3 years ago

Is your feature request related to a problem? Please describe. In most EE containers I do something like this in the web.xml

<context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>${jsf.stage}</param-value>
    </context-param>

So I can dynamically set based on Maven for Development or Production. This does not work in OpenLiberty as it seems to use the in place web.xml and does not allow substitution.

Describe the solution you'd like Similar to how its done in Quarkus when running in Dev liberty:dev mode set stage to Development When running from JAR or deployment set to Production mode.

volosied commented 3 years ago

Hi @melloware,

The only way I'm aware of is through maven. Also, it appears you missing a bracket - {. Not sure if it's a typo or not.

Add the following plugin to you pom:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webResources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/webapp</directory>
                <includes>
                    <include>**/web.xml</include>
                </includes>
            </resource>
        </webResources>
        <warSourceDirectory>src/main/webapp</warSourceDirectory>
        <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
    </configuration>
</plugin>

and property:

`

Development ` Hope it helps. Source: https://stackoverflow.com/questions/15355708/how-to-replace-a-value-in-web-xml-with-a-maven-property
yeekangc commented 3 years ago

Cc @ericglau

melloware commented 3 years ago

@volosied I agree but that does not work with Liberty you get this error...

[INFO] [WARNING ] Wrong value in context init parameter 'javax.faces.PROJECT_STAGE' (='${liberty.var.jsf.stage}'), using default value 'Production'

@yeekangc @ericglau My project is here: https://github.com/melloware/liberty-faces

melloware commented 3 years ago

When properly running in JSF Development mode you will see this in console...

[INFO] [AUDIT   ] CWWKT0016I: Web application available (default_host): http://laptop-tjeaghk8:8080/showcase/
[INFO] [WARNING ]
[INFO]
[INFO] *******************************************************************
[INFO] *** WARNING: Apache MyFaces-2 is running in DEVELOPMENT mode.   ***
[INFO] ***                                         ^^^^^^^^^^^         ***
[INFO] *** Do NOT deploy to your live server(s) without changing this. ***
[INFO] *** See Application#getProjectStage() for more information.     ***
[INFO] *******************************************************************
[INFO]
[INFO] [AUDIT   ] CWWKZ0001I: Application liberty-faces started in 11.122 seconds.
volosied commented 3 years ago

Thank you for sharing the code. I see what you mean now. Liberty's loose config is looking at the the web.xml in the src/main/webapp/WEB-INF/web.xml directly, and no variable substitution occurs in-between.

I agree this would be a great enchantment for the liberty-maven-plugin. I'm not as familiar with the plugin, but other team members are looking into this further. Thanks!

scottkurz commented 3 years ago

Moving the discussion into the liberty-maven-plugin repo issue: https://github.com/OpenLiberty/ci.maven/issues/1104 Thanks for bringing it up.

Going to close this issue now.