The New Relic Java Agent can be passed environment variables at run/deploy time.
If you want to set the app name with an environment variable you can do so with:
export NEW_RELIC_APP_NAME="Your App Name Here"
You can also pass the app name at runtime with a Java system property like so:
-Dnewrelic.config.app_name="Your App Name Here"
Also, the order of precedence is environment variable, system property and then config file. The environment variable overrides all other settings and the system property will override the config file but not the environment variable.