简体   繁体   English

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

[英]Create a WAR from the java files using Gradle script

My directory sturcture is, 我的目录结构是
C:\\Grapher\\src\\ *.java C:\\ Grapher \\ src \\ * .java
C:\\Grapher\\lib\\ *.jar C:\\ Grapher \\ lib \\ * .jar

There are many java files and many jar dependencies. 有许多Java文件和许多jar依赖项。 I want to create a tomcat deployable WAR. 我想创建一个tomcat可部署的WAR。
Can any one suggest me how to create a WAR using a gradle script? 谁能建议我如何使用gradle脚本创建WAR? What are the dependencies to be included in Gradle to create a WAR. 在Gradle中创建WAR需要包含哪些依赖项。

Have you read and understood https://docs.gradle.org/current/userguide/war_plugin.html ? 您是否已阅读并理解https://docs.gradle.org/current/userguide/war_plugin.html

The War plugin adds two dependency configurations named providedCompile and providedRuntime. War插件添加了两个依赖配置,分别名为provideCompile和providerRuntime。 Those two configurations have the same scope as the respective compile and runtime configurations, except that they are not added to the WAR archive. 这两个配置与各自的编译和运行时配置具有相同的作用域,只是它们没有添加到WAR存档中。 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. 假设您将commons-httpclient:commons-httpclient:3.0添加到提供的任何配置中。 This dependency has a dependency on commons-codec. 此依赖项与commons编解码器有关。 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. 因为这是“提供的”配置,所以这意味着即使commons编解码器库是编译配置的显式依赖项,也不会将这些依赖项都添加到WAR中。 If you don't want this transitive behavior, simply declare your provided dependencies like commons-httpclient:commons-httpclient:3.0@jar. 如果您不希望这种传递行为,只需声明您提供的依赖项,例如commons-httpclient:commons-httpclient:3.0@jar。

If you use providedCompile or providedRuntime, those dependencies will not be added to your war archive. 如果使用provideCompile或providerRuntime,这些依赖项将不会添加到您的war归档文件中。

The folder structure you need to have in your project is: 您的项目中需要的文件夹结构为:

app
 |-src
    |-main
       |-java
       |-webapp

In the java folder you add your own packages and classes. 在java文件夹中,添加您自己的包和类。 In the webapp folder you add web content if your application makes use of such items. 如果您的应用程序使用了此类内容,则在webapp文件夹中添加Web内容。

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

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