java - 使用Gradle脚本从Java文件创建WAR

标签 java class gradle ant war

我的目录结构是
C:\ Grapher \ src \ * .java
C:\ Grapher \ lib \ * .jar

有许多Java文件和许多jar依赖项。我想创建一个tomcat可部署的WAR。
有人可以建议我如何使用gradle脚本创建WAR吗?在Gradle中创建WAR需要包含哪些依赖项。

最佳答案

您阅读并理解https://docs.gradle.org/current/userguide/war_plugin.html吗?

The War plugin adds two dependency configurations named providedCompile and providedRuntime. Those two configurations have the same scope as the respective compile and runtime configurations, except that they are not added to the WAR archive. It is important to note that those provided configurations work transitively. Let's say you add commons-httpclient:commons-httpclient:3.0 to any of the provided configurations. This dependency has a dependency on commons-codec. Because this is a “provided” configuration, this means that neither of these dependencies will be added to your WAR, even if the commons-codec library is an explicit dependency of your compile configuration. If you don't want this transitive behavior, simply declare your provided dependencies like commons-httpclient:commons-httpclient:3.0@jar.



如果您使用provideCompile或providerRuntime,这些依赖项将不会添加到您的 war 文件中。

您的项目中需要的文件夹结构为:
app
 |-src
    |-main
       |-java
       |-webapp

在java文件夹中,添加您自己的包和类。如果您的应用程序使用了此类内容,则在webapp文件夹中添加Web内容。

关于java - 使用Gradle脚本从Java文件创建WAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45328300/

相关文章:

java - 计算直线与 x 轴之间的角度

连接到服务器时的 Java BufferedWriter - 空指针异常 - 聊天应用程序

java - 迭代二维数组错误

java - 从类中检索 ArrayList 信息

android - 无法在 Travis CI/Android SDK v20 上使用支持库构建

java - 如何发出和处理自定义事件?

java - 如何在类构造函数中初始化数组

c++ - C++ 字符串类可以进行指针运算吗?

android - 无法通知项目评估监听器 > javax/xml/bind/annotation/XmlSchema

maven - 带有 Maven 依赖项的 Jersey + Gradle 不起作用