redhat-developer / vscode-server-connector

📦 Connects Visual Studio Code to your server adapters and run, deploy apps !!
Eclipse Public License 2.0
56 stars 26 forks source link

Configure environment variables for tomcat server #541

Closed kakanghosh closed 2 years ago

kakanghosh commented 2 years ago

Currently, I am trying to configure env variables for the tomcat server to access it from the application.

I have tried, to keep the setenv.sh in the tomcat/bin folder but it is not working for me.

If I have exposed the env values from the .zshrc then it somehow works but not in every case, maybe it required a system restart for that.

Is there any way how it can be achieved easily without exporting from the .zshrc/.bashrc file or what is the correct way to do it in this case?

Additional information: OS: Linux x64 5.15.0-39-generic snap ( Ubuntu 22.04 LTS) Vscode: Version: 1.68.1 Server: tomcat 9

robstryker commented 2 years ago

Hrmm... this is a tough one.

There's a few things we do to manipulate environment variables. First, a server adapter has a file with its configuration data. You can edit this data to add the mapProperty.launch.env key like in the following example:

  "id": "Tomcat 9.x",
  "id-set": "true",
  "mapProperty.launch.env": {
    "a": "b"
  },
  "org.jboss.tools.rsp.server.typeId": "org.jboss.ide.eclipse.as.server.tomcat.90",

Generally, a launched tomcat (when launched via our tools) inherits (and adds to) the environment passed to it by the RSP, the background java program that manages all the servers and stuff. The RSP is launched by the vscode extension. This is the code we use to have the vscode extension launch the rsp:

    cpProcess = cp.spawn(java, [`-Drsp.server.port=${port}`, `-Dorg.jboss.tools.rsp.id=${rspid}`, '-Dlogback.configurationFile=./conf/logback.xml', '-jar', felix], { cwd: location });

When looking at cp.spawn, it seems that last parameter, {cwd: location} is the options parameter, which should default to { cwd: undefined, env: process.env } if its not set. However, it looks like we're setting it to {cwd: location}, and it may not be inheriting the environment.

Thanks for the heads up. I might be able to make this a bit more functional if I just change it to {cwd: location, env: process.env} instead.

robstryker commented 2 years ago

You should be aware, though, that the environment passed in to an application depends on where you're launching it from. If you launch code from the command line, you should easily inherit your zsh environment. But if you launch it via some shortcut or start key, there's no guarantee that the environment passed in will match your expectations or when you launch via command line. Just to let you know :)

robstryker commented 2 years ago

So I've made a patch that verifies launching code from the command line will pass the env to the RSP which will also pass the environment to the spawned tomcat. Hope this helps. Not sure when I'll release it just yet.