grails 4.x: Creating a WAR with a custom env always runs under development

867 Views Asked by At

I can't get my custom environment to run under Tomcat. It always loads the development profile.

I create a WAR with the following under Grails 4.0.5:

grails -Dgrails.env=qa war 

The resulting grails.build.info looks correct:

info.app.version=2.0.7
info.app.name=myapp
grails.env=qa
info.app.grailsVersion=4.0.5

However, when I drop it into Tomcat 8 and run, I get this:

 [ost-startStop-1] com.myapp.ApplicationLoader        : The following profiles are active: development

Running standalone, though, works just fine:

./gradlew -Dgrails.env=qa bootRun 
1

There are 1 best solutions below

0
On

grails.util.Environment, defines a number of pre-configured environments.

Environment APPLICATION
Environment CUSTOM
Environment DEVELOPMENT
Environment PRODUCTION
Environment TEST

In application.yml we get pre-configured development, test, and production environments. So if we want to add custom environments we add similarly. In your case it will be qa.

With Grails command line we can execute any command within the context of a specific environment. The format is:

grails [environment] [command name]

Suppose if want to create a WAR for the test environment you wound run:

grails test war

To target other environments you can pass a grails.env variable to any command:

grails -Dgrails.env=UAT run-app

I create a WAR with the following under Grails 4.0.5:

grails -Dgrails.env=qa war

Yes, all looks good as per grails documentation and configuration.

I have Created POC app for same with Grails 4.0.5 and also downloaded external tomcat apache-tomcat-8.5.63.

Tomcat and grails

My application.yml with qa ENV:

qa env

Running standalone, though, works just fine:

./gradlew -Dgrails.env=qa bootRun

Yes. This also works fine. So, now i have created war file with grails -Dgrails.env=qa war Then i started my tomcat and dropped my poc-app-0.1.war file into tomcat.

enter image description here

when tomcat deployed/extracted my war, entered local url into browser.

enter image description here

You can see in above image, Environment is qa

So everything is running as i passed to env while creating war.

I tested with multiple environments, both pre-configured and custom environments. But did not got any issue like created war for qa and running on dev.

Also i have tested with java -jar poc-app-0.1.war and it's running on same env as we given.

Application details: app details

and tomcat version is apache-tomcat-8.5.63

It may be some versions or configuration issue with your app.

Please refer this link of my poc. Can you please try to create war and deploy in same way to your tomcat and let me know.

If you are still getting issue, then please share your minimal code or poc.

Even i got one more similar kind of issue on grails repo, please do refer this.

I have followed lot of documentation and references but still not able to reproduce your issue.

Links: