Grails "war" command, how to set system property - grails

I'm running grails prod war to create my app's .war file. The problem is, I need to somehow set a system property that can be accessed in grails-app/conf/Config.groovy when that .war is being built.
How can I do this? Grails version 2.1.0

You need to set this property when the war is being launched, not when it's being built. If the app is being hosted by Tomcat (or similar) you would typically adds this as a parameter to the java command that launches Tomcat.

grails -Dproperty=value prod war

Related

How to build a custom environment in Grails

I'm trying to add a new environment to our Grails WAR (let's call it "staging"). I can manage the configuration in Config.groovy and DataSource.groovy and access the right configuration at run-time with -Dgrails.env, but how do I build this WAR?
The Grails documentation does not cover this case and the links on the page seem to be outdated.
You are so very close to having the right combination in your question, this should work:
grails -Dgrails.env=staging war
Actually, the documentation for the war command even uses 'staging' as the environment used.
The same goes for any environment-specific command:
grails -Dgrails.env=<environment name> <command>

How do I know what webserver gradle / grails is using?

This thread: Gradle / Grails application describes how to set up the grails plugin for gradle.
The command gradle grails-run-app tries to start the grails application on port 8080. What webserver is gradle using here?
Does it have an embedded one? If so how can I access / configure it?
It just shelling out to the same thing that Grails would have done without Gradle, as if you had run grails run-app. That depends on which server plugin you have installed. By default it's http://grails.org/plugin/tomcat, but you can switch to http://grails.org/plugin/jetty by changing the values in grails-app/conf/BuildConfig.groovy
Gradle is nothing but a build and config tool like maven. When you use it with Grails app the dependencies are managed by it as it happens when maven is used.
When you use gradle grails-run-app it does nothing more other than running grails run-app from its own context. The same embedded Tomcat server is used by default.

Doesn't grails run-app create a war?

Doesn't a grails run-app create a WAR file(exploded) in the embedded Tomcat Container? If so what is the difference between grails run-app and grails run-war command?
Is it possible to view the web app directory under the embedded Tomcat Directory after the execution of grails run-app command?
The grails-app command starts an embedded Tomcat server and configures its context paths so that it can look up everything it needs from their original filesystem paths. Therefore there is no single place where everything would be gathered as would be when running an exploded web application archive.
No, run-app doesn't create a war. It starts the Tomcat server and configures it programmatically as an exploded war.

Grails war command defaults to development environment under netbeans

When I generate the war in my grails app via right-click / run grails / command / war, it shows "Environment set to development", having it run without parameters. Why is this happening when according to the docs it should default to production (which is what I need)?
BTW, is there a way having built the whole grails application with NetBeans to use the command line to generate the wars ?
Versions: NetBeans 6.7.1, Grails 1.2
OS: Ubuntu 9.1
Thanks
The netbeans plugin is probably running the command "grails dev war" which creates a war file based on the development settings. The normal "grails war" command uses production settings.
You should just be able to change to the directory containing your grails-app and src folders and run the command
grails war
This assumes that you have grails installed and on your path.
No, only that grails war may assume it to be a development. I suggest you specifically type as follow:
grails prod war
you can modify the proyect file gradle.properties and add
org.gradle.jvmargs=-Dgrails.env=dev //for development
org.gradle.jvmargs=-Dgrails.env=prod //for production enviroment
Check https://docs.grails.org/latest/guide/gettingStarted.html

Create grails war without version number

How do I create a grails war file so that it doesn't have the version number
(e.g. foo-0.1.war)
attached to the end when I execute the 'grails war' command?
In case anybody comes upon this article and is using Grails 1.3.x, the configuration option has changed from grails.war.destFile in Config.groovy to being grails.project.war.file in BuildConfig.groovy.
Also the file name is relative to the project workspace, so it should have a value like:
grails.project.war.file = "target/${appName}.war"
This is according to the latest Grails documentation.
I think you can specify the war name in the war command.
grails war foo.war
Also check the latest Grails documentation for where to set this as a configuration option. See the other answers for details.
From the Grails Documentation, Chapter 17, Deployment
There are also many ways in which you can customise the WAR file that is
created. For example, you can specify
a path (either absolute or relative)
to the command that instructs it where
to place the file and what name to
give it:
grails war /opt/java/tomcat-5.5.24/foobar.war
Alternatively, you can add a line to
Config.groovy that changes the default
location and filename:
grails.war.destFile = "foobar-prod.war"
Of course, any command line argument
that you provide overrides this
setting.
Rolling up the other excellent answers. There are several options:
Explicitly set it on the command line: grails war foo.war
Set the app.version property to empty in application.properties will cause the war to be named foo.war.
Explicitly set the name of the war using the grails.war.destFile property in Config.groovy
Grails 3.x has switched to gradle and uses the war plugin. You can just specify name like this in the build.gradle file:
war {
archiveName 'foo.war'
}
Another way to generate war files without version number is to keep the property, app.version, empty in the application.properties
I am kind of late to the party... but anyway:
I think the reason behind removing the version number is to eliminate the need to rename the war file so it deploys on "correct" context path /appName. If that's the case then a better option is to use a versioned war filename so you can deploy multiple versions at the same time on tomcat using the following naming pattern in grails-app/conf/BuildConfig.groovy:
grails.project.war.file = "target/${appName}##${appVersion}.war"
As explained in http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Parallel_deployment
This method applies to wars in general, not only grails' wars.

Resources