mvn package not recognizing OS environment variables

Viewed 28

I'm trying to deploy an API do AWS EC2.

And this API has environment variables inside application.properties, such as $DB_HOST, $DB_USER and $DB_PASS, and then I set them at

vim .bashrc
source .bashrc

All the process occurs alright for the deployment, but when I run

sudo mvn package

It doesn't recognize the environment variables setted from the OS (linux) and build fail. I can't really find any similar solution here.

Also tried putting them inside the /˜profile with

nano /˜profile
source /˜profile

Anyone has any ideas? :)

1 Answers

When you use sudo, it doesn't use your environment variables but those of the root user (or in case you use sudo -u <user>, that user).

I suggest not using sudo without specifying a user. That means that the code is running as root, which is a big security risk. I'd create a new user dedicated for your application. You can configure that user's environment variables as well.

Related