我的目录结构是
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/