Skip to content

Instantly share code, notes, and snippets.

@wildoctopus
Created April 3, 2018 16:31
Show Gist options
  • Save wildoctopus/8f7cdb4ba837b6a4e8b4c513488fba4e to your computer and use it in GitHub Desktop.
Save wildoctopus/8f7cdb4ba837b6a4e8b4c513488fba4e to your computer and use it in GitHub Desktop.
Snippet of code using Grunt to Generate .war file to deploy on any Tomcat server
// Save this snippet as grunt-war.js and run with "grunt --gruntfile grunt-war.js war" at the command line.
// Assumes simple layout:
// -project
// --build (The folder where the generated grunt-magic.war file will go)
// --src (all the source code, html, etc)
// --- index.html (The file name must match up with the webxml_welcome: property below)
module.exports = function ( grunt ) {
grunt.loadNpmTasks( 'grunt-war' );
var taskConfig = {
war: {
target: {
options: {
war_verbose: true,
war_dist_folder: 'build', // Folder path seperator added at runtime.
war_name: 'grunt-magic', // .war will be appended if omitted
webxml_welcome: 'index.html',
webxml_display_name: 'Grunt WAR'
},
files: [
{
expand: true,
cwd: 'src', //working folder which contains html , js or etc files. for example "app" or "src" folder. In most cases its app or src only.
src: ['**'],
dest: ''
}
]
}
}
};
grunt.initConfig( taskConfig );
};
// Note
// You can directly embedd the war task in grunt.initConfig too. as shown below -
grunt.loadNpmTasks('grunt-war');
grunt.initConfig({
/*
* Build a WAR (web archive) without Maven or the JVM installed.
*/
war: {
target: {
options: {
war_dist_folder: '<%= build_dir %>', //In this way , its create folder in main C drive, if you have projetc created there. Not insed the project folder, so make sure you have admin rights to create folder in that location.
war_name: 'grunt-magic',
webxml_welcome: 'index.html',
webxml_display_name: 'Grunt WAR',
webxml_mime_mapping: [ { extension: 'woff', mime_type: 'application/font-woff' } ]
},
files: [
{
expand: true,
cwd: 'src',
src: ['**'],
dest: ''
}
]
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment