繁体   English   中英

如何使用Grunt将jar文件复制到WEB-INF / lib

[英]How to copy jar files to WEB-INF/lib using Grunt

我是Grunt build的新手。 这里我的要求是,创建WEB-INF / lib目录并在使用Grunt构建执行war任务时将Jar文件复制到其中。

以下是我war.js的样本:

module.exports = {
/*
 * Build a WAR (web archive) without Maven or the JVM installed.
 */

target: {
    options: {
        war_dist_folder: 'deploy',
        /* Folder to generate the WAR into */
        war_name: 'mySampleApp',
        /* The name fo the WAR file (.war will be the extension) */
        webxml_webapp_version: '2.5',
        war_extras: [{
                filename: 'WEB-INF/weblogic.xml',
                data: '<?xml version = "1.0" encoding = "US-ASCII"?> \n\n\
                        <weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \n\n\
                        xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" \n\n\
                        xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app"> \n\n\
                            <context-root>my-sample-app</context-root> \n\n\
                            <session-descriptor> \n\n\
                              <timeout-secs>1800</timeout-secs> \n\n\
                               <cookie-name>JSESSIONID</cookie-name> \n\n\
                                <cookie-path>/my-sample-app</cookie-path>  \n\n\
                                <url-rewriting-enabled>false</url-rewriting-enabled>  \n\n\
                            </session-descriptor> \n\n\
                        </weblogic-web-app>'
            }],
        /* the war_extras are extra files to be generated, needed since grunt-war doesn't create a weblogic.xml */
        webxml_welcome: 'index.html',
        /* to point web.xml to the default page */
        webxml_webapp_extras: ['<login-config />\n', 
                               '<session-config>\n    \n\
                                    <session-timeout>\n    30\n    </session-timeout>\n\n\
                                </session-config>\n',
                                '<servlet>\n   \n\
                                    <servlet-name>\n    MyServlet\n    </servlet-name>\n\n\
                                    <servlet-class>com.sample.servlet.MyServlet</servlet-class>\n\n\
                                </servlet>\n',
                                '<servlet-mapping>\n\
                                    <servlet-name>MyServlet</servlet-name>\n\
                                    <url-pattern>/maySampleApp</url-pattern>    \n\
                                </servlet-mapping>'
                              ]

    },
    files: [{
            expand: true,
            cwd: 'release',
            /* find the source files for the WAR in the /release folder */
            src: ['**'],
            dest: ''
        }]
    }
};

请提供创建WEB-INF / lib目录并将jar文件复制到其中的说明。

你有没有尝试过“简单”的东西( files采用“数组”参数......这个特殊的选项字段并没有真正记录在grunt-war中 ):

// ...,
files: [{
        expand: true,
        // better ...no cwd, "copy single file tree" @see [2]
        src: ['release/*'],
        dest: ''
    }, // a second "files" object! (and my particular answer)
    {
        // expand: false, assuming/hoping for a flat *.jar structure (all in one folder)
        // cwd: '', NO cwd ...
        /* GET all files with "lib/*.jar" "matcher" */
        src: ['lib/*.jar'],
        /* ... and "destinate" into "WEB-INF/lib" */
        dest: 'WEB-INF/lib'
    }
] // ...

没有保修,没有测试,只是一个gutshot! :)

当你的“lib”文件夹结构过于花哨时,你必须使用epxandcwd ,参见: [1][2] ,@ Robc的评论。

当所有这一切都以grunt-war插件失败时,我会尝试 war执行之前 (罐子) 复制到“release / WEB-INF / lib”中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM