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.15k stars 592 forks source link

How to configure server.xml to allow multiple server.env files for different applications? #25719

Open chakravarthi2u opened 1 year ago

chakravarthi2u commented 1 year ago

Dear Liberty team,

I have two web applications app1 and app2. app1 will use server.env.app1 and app2 will use server.env.app2.

How to configure server.xml webApplication section to configure different server.env files for each deployed applications?

Thanks for helping.

jhanders34 commented 1 year ago

server.env sets process system environment variables that can be gotten from the System.getenv() method in Java. Processes and Java do not have a way to have more than one set of system environment variables.

By providing more details about what you are trying to accomplish, we may be able to come up with a solution. System environment variables aren't going to be the way you are going to be able to do it if you need two applications in the same server have different values for the same variable since a system variable can only have one value.

chakravarthi2u commented 1 year ago

I have one web application running in liberty server which will connect to backend server(specified as properties) in server.env

I want to run one more similar application points to different backend server. In this case, i cant use same property in server.env file. That is i want to customize backend server urls in different server.env files and wants to point in webApplication section in server.xml file.

<webApplication contextRoot="/" location="app.war">
    <server.env.includes path="server.env.1"/>
</webApplication>
<webApplication contextRoot="/test" location="app2.war">
    <server.env.includes path="server.env.2"/>
</webApplication>

Both server.env.1 and server.env.2 files will have almost same properties with different values. These files will be used by applications.

NottyCode commented 1 year ago

As Jared said you cannot use server.env file for this. The server.env file is to provide the environment for the server. It is processed in the shell by the shell and can only apply process wide. This isn't a Liberty limitation, but this is a limitation produced by the shell and Java.

Perhaps if you explained how your applications will be accessing this configuration we might be able to suggest alternative options, but if you really need to read this from the environment you would need two servers.

chakravarthi2u commented 1 year ago

Thanks for the details. I will consider these points.