Create war file in grails using GGTS - grails

I have done a small application in Grails, and now I need to generate a war file to test it on server. I generated a war using command grails:war. It has generated the file but named it as myapp-01.war. I don't want this, I need a war where the file name should be same as the project; like myapp.war

Try:
grails war myapp.war
Additional options: http://docs.grails.org/3.1.1/ref/Command%20Line/war.html

Related

How to exclude grails plugin jar from war file

Grails 3.2.5. Build.gradle has mail plugin:
compile "org.grails.plugins:mail:2.0.0.RC6"
In deploying a war to production I need to remove javax.mail-1.5.6.jar from WEB-INF/lib since that jar must be in the Tomcat lib when using a JNDI mail resource. So how do I keep the mail plugin but remove the offending jar file from the war? I knew how to do this in Grails 2.x. Via the gradle war task in build.gradle I have tried to exclude the file (doesn't work - the jar drifts in from a plugin somehow), and have tried to filter the file out. When I build the war I get two files - "app-0.1.war" and "app-0.1.war.original". The "original" file has the WEB-INF/lib/javax.mail jar filtered out, but the real, complete war still has it.
So how do I prevent that plugin jar from getting into the war file? Thanks.
One way to do it is with something like this:
war {
rootSpec.exclude '**/javax.mail*.jar'
}
(you may need to adjust depending on whether or not you want to also exclude the javax.mail-api jar file along with the javax.mail jar)
See https://github.com/jeffbrown/excludejar/blob/67734ac0c65cdbead468f1e65bcfc29041cd2279/build.gradle#L70-L72

Grails 3.1.5 dont produces jar file

In version to 3.1.5, the command "package" not produces a jar file in "project/build/libs"
I ran a simple "create-app" and "package" with versions 3.0.9 and 3.1.5. Only the first produces a jar file. No error appears in both.
Someone knows how I create a executable JAR, in version 3.1.5?
The documentation states...
If you prefer not to operate a separate Servlet container then you can
simply run the Grails WAR file as a regular Java application.
And then provides the following example:
grails war
java -Dgrails.env=prod -jar build/libs/mywar-0.1.war
So basically, the generated war file is a jar file.

Create Grails 3 WAR without version number

In Grails 2 we could define WAR filename like this:
grails.project.war.file = "target/${appName}.war"
How can I override the war filename in Grails 3?
Thanks Jeff.
I have added line like thisin build.gradle:
war {
archiveName "${war.baseName}.war"
}
In build.gradle you can do something like war.archiveName='jeff.war'. See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.War.html#org.gradle.api.tasks.bundling.War%3aarchiveName.
A more detailed answer: Add this to wrapper task in build.gradle so it creates different war file name based on each environment.
war.archiveName="${war.baseName}_${grails.util.Environment.current.name}.war"
Then create war file like this.
grails -Dgrails.env=staging war

how grails 3.0.x create custom war name with different file suffix

In grails 3.0.(1,2,3) the war file exist under the folder 'build/libs'
However, I want to rename the war name with different file suffix, like "app.tar.gz", without the version.
the google result is all about grails 2.x
I put the grails.project.war.file = "target/${appName}.tar.gz" in the file application.groovy under the folder conf but it's useless.
Plz help me, i googled and try to find solution in the source code BuildSettings.groovy, but the it's no use.
As of grails version 3, the build tool is gradle, you would need to change those parameters from your build.gradle file
If you do not want the version as part of your package name, you will need to comment (or remove) the version from build.gradle file
for example, running the following
fhenri#machine:~/project/grails/sample307$ grails -version
| Grails Version: 3.0.7
| Groovy Version: 2.4.4
| JVM Version: 1.8.0_51
fhenri#machine:~/project/grails/sample307$ grails package
...
fhenri#machine:~/project/grails/sample307$ find . -name *.war
./build/libs/sample-0.1.war
After you remove the version from `build.gradle` file
fhenri#machine:~/project/grails/sample307$ grails package
...
fhenri#machine:~/project/grails/sample307$ find . -name *.war
./build/libs/sample.war
Grails uses the war gradle plugin, from the plugin the pattern to make the archive name is [baseName]-[appendix]-[version]-[classifier].[extension], the version already comes from the build.gradle file as generated from grails create-app
each of this can be overwritten in a war closure, for example, an excerpt of the build.gradle could be
version "0.1"
war {
appendix "so-test"
version "1.0"
}
The generated war file will be sample-so-test-1.0.war the version will come from the war closure.
So if you want to keep the mail version properties but do not want to generate the version in your generated war name you can overwritten the property with an empty value
version "0.1"
war {
version ""
}
will generate a war file without the version information, but still you could keep it for you if you want to use it somewhere else.
To package as tar/zip, you can
follow the documentation for grails 3: http://grails.github.io/grails-doc/latest/guide/deployment.html (chapter on TAR/ZIP distribution)
In build.gradle, after applying the gradle war plugin you can do this:
war {
archiveName = "ROOT.war"
}
And a ROOT.war file will be created at build/libs

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