![Spring 5.0 Cookbook](https://wfqqreader-1252317822.image.myqcloud.com/cover/699/36700699/b_36700699.jpg)
上QQ阅读APP看书,第一时间看更新
How to do it...
- Open the gradle.build file and add the buildScript() function that accepts a closure containing all libraries needed to be referenced in classpath. At this step, we need to import gradle-tomcat-plugin under the group com.bmuschko:
buildscript { repositories { jcenter() } dependencies { classpath 'com.bmuschko:gradle-tomcat-plugin:2.0' } }
- Add the following libraries to the classpath:
apply plugin: 'com.bmuschko.tomcat' apply plugin: 'com.bmuschko.tomcat-base'
- (Optional) Add the following Tomcat 9.0 libraries that enable Gradle to run embedded Tomcat through the tomcatRun() and tomatRunWar() functions:
dependencies { def tomcatVersion = '9.0.0.M9' tomcat "org.apache.tomcat.embed:tomcat-embed
core:${tomcatVersion}", "org.apache.tomcat.embed:tomcat-embed-logging- juli:${tomcatVersion}" tomcat("org.apache.tomcat.embed:tomcat-embed- jasper:${tomcatVersion}") { exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj' }
}
- (Optional) Configure Tomcat 9 details through the tomcat() function:
tomcat { httpsPort = 8443 enableSSL = true users { user { username = 'packt' password = 'packt' roles = ['manager-gui', 'manager-script'] } } }
- To deploy the project into the installed Tomcat 9, create a Gradle task deploy that copies the WAR file to the /webapp folder:
task deploy (dependsOn: war){ copy { from "build/libs" into "C:\MyFiles\Development\Servers\Tomcat9.0\webapps" include "*.war" } }
- You can now run deploy in the Gradle Task Launcher.
![](https://epubservercos.yuewen.com/0AC9E4/19470403601617006/epubprivate/OEBPS/Images/e0b44df4-dcd6-4334-b888-07e725f950d6.png?sign=1739012201-snhp56FxCAAedSUwH7zVbyiM2eoBxL6g-0-38a82f1f07b42390573c15c8e95b91d5)