OJET: Build and Deploy in an Application Server

There are some other sources where an Oracle JET Application is packaged and deployed as a WAR in Oracle WebLogic Application Server
They may look bit old or maybe because they call directly grunt tasks by using the grunt-cli.

In this post I will update a bit these posts in Oracle JET 6.1.0 and the usage of ojet build (instead of calling the grunt tasks) for also building the corresponding WAR file.

The example can be found in my GIT repository: https://github.com/DanielMerchan/ojet-examples

Let's start...
  1. Install grunt-war module in your Oracle JET Application.

    npm install grunt-war --save-dev
  2. Create a war.js (or call it whatever you want) in /scripts/grunt/config folder under your souce files.

    This is a sample code inside of it, check https://www.npmjs.com/package/grunt-war as there are many options you can include if you need more complex web.xml.
    Note: The usage of <% xxx %> is for use as replacement later with the information we need.

    module.exports = {
    
        /*
         * Build a WAR (web archive) without Maven or the JVM installed.
         *
         * Template strings in the <%= %> tags are set in the data section of Gruntfile.js,
         *  or you can hardcode the strings here instead
         */
    
        target: {
            options: {
                war_dist_folder: '<%= distdir %>',      /* Folder to generate the WAR into, set in data section of Gruntfile.js */
                war_name: '<%= appname %>',            /* The name for the WAR file (.war will be the extension) */
                webxml_webapp_version: '2.5', /* I needed this older version for JCS-SX */
                webxml_display_name: '<%= appname %>',
                war_extras: [{ filename: 'grunt-war-credits.txt', data: 'This line will appear in the file!\n see http://likeahouseafire.com/2017/08/09/updated-using-grunt-to-create-war-jet3x/ ' },
                { filename: 'WEB-INF/weblogic.xml', data: '\n\n  \n    true\n    true\n  \n  /<%= appname %>\n' }],
                /* the war_extras are extra files to be generated, needed since grunt-war doesn't create a weblogic.xml */                                          /* also notice that we're using the <%= appname %> variable in there */
                webxml_welcome: 'index.html', /* to point web.xml to the default page */
                webxml_webapp_extras: ['\n', '\n    \n    30\n    \n\n']
                /* some extra settings for weijetb.xml to work with JCS-SX */
    
            },
            files: [
                {
                    expand: true,
                    cwd: '<%= appdir %>',             /* find the source files for the WAR in the /web folder, set in Gruntfile.js */
                    src: ['**'],
                    dest: ''
                }
            ]
        }
    };
  3. Open the after_build.js script. Here we will make sure that after we build our sources (dev or release mode) we also invoke the war grunt task we just initiated within the code.

    /**
      Copyright (c) 2015, 2019, Oracle and/or its affiliates.
      The Universal Permissive License (UPL), Version 1.0
    */
    
    'use strict';
    
    const path = require('path');
    const grunt = require('grunt');
    
    module.exports = function (configObj) {
      require('load-grunt-config')(grunt, {
        configPath: path.join(process.cwd(), 'scripts/grunt/config'),
        data: {
          appname: path.basename(process.cwd()),  // same as project directory name, accessible with '<%= appname %>'
          appdir: 'web',  // accessible with '<%= appdir %>'
          distdir: 'dist'  // accessible with '<%= distdir %>'
        }
      });
    
      return new Promise((resolve, reject) => {
        console.log("Running after_build hook.");
        grunt.tasks(['war']);
        resolve();
      });
    };
    
  4. Execute ojet build --release. Our  WAR file is generated in the dist folder.

  5. Deploy the WAR file into your Application Server. In this case WebLogic Application Server.

  6. Test your application is accessible.

Comments

  1. Thanks for providing an updated instruction list. I'm new to grunt, so fumbling my way through!
    Is a gruntfile.js required somewhere? I'm getting an error "Fatal error: Unable to find Gruntfile." when I do my ojet build --release.
    Also I've assumed the "" at the end of the war.js section shouldn't be there.

    ReplyDelete
    Replies
    1. Oh it stripped the HTML.. the "" should contain </login-config>

      Delete

Post a Comment

Popular posts from this blog

OJET: Inter-Module communication in TypeScript Template

OJET: Select All options using only Checkboxset