gradle war:如何构建jar,而不是类 [英] gradle war: how to build jar, not classes

查看:78
本文介绍了gradle war:如何构建jar,而不是类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gradle war插件:如何构建一个jar并将其添加到war?

Gradle war plugin: how to build a jar and add it to war?

projectRoot/
        src/main/java
        src/main/resources
        src/main/webapp

  1. 从Java源代码和资源中构建一个jar(foo.jar).
  2. 将罐子添加到战争的WEB-INF/lib下.

  1. build a jar (foo.jar) from the java source code and resources.
  2. add the jar under the WEB-INF/lib of the war.

WEB-INF/lib/foo.jar

WEB-INF/lib/foo.jar

战争任务默认情况下不会构建jar,并在WEB-INF/classes下添加所有Java类和资源.

The war task will not build a jar by default, and add all java classes and resources under WEB-INF/classes.

The War plugin extends the Java plugin to add support for assembling web
application WAR files. It disables the default JAR archive generation of the 
Java plugin and adds a default WAR archive task.

有一种方法可以启用Jar生成并让任务战争取决于任务jar?

There is a way to enable the Jar generation and let task war depends on task jar?

推荐答案

不确定东部水域是否仍然需要答案,希望其他有相同问题的人也能找到帮助

not sure if eastwater still needs the answer, hope others with the same problem will find this helpful

您可以在build.gradle中添加/配置战争任务

you can add/configure the war task in build.gradle

war {
    classpath = classpath - sourceSets.main.output
    from (jar) {
        into 'WEB-INF/lib'
    }
}

一旦构建成功,在build/libs文件夹中,您将看到生成的jar和包含生成的jar而不是类的战争

once build succeed, in build/libs folder you'll see the generated jar and the war containing the generated jar instead of classes

这篇关于gradle war:如何构建jar,而不是类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆