[英]Run multiple war's with gradle and tomcat in NetBeans IDE
我正在使用NetBeans 8.0.2 IDE,gradle和tomcat6。我已經創建了一個帶有一些子項目的根項目:
我想知道的是,部署rootproject(或前端),然后將front-war和rest-war部署到嵌入式和本地tomcat服務器。 我嘗試使用標識符為com.bmuschko.cargo的Cargo插件,但是沒有正確配置它的方法,因此它可以像我想要的那樣運行。
互聯網上的一些信息說,這無法正常運行或無法實現...
有誰知道,如何解決這個問題? 我應該改用Maven嗎?
這是我的配置文件:
Rootproject build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-cargo-plugin:2.0.3'
}
}
import org.gradle.api.artifacts.*
apply plugin: 'base' // To add "clean" task to the root project.
apply plugin: 'com.bmuschko.cargo'
subprojects {
apply from: rootProject.file('common.gradle')
}
task wrapper(type: Wrapper, description: 'Creates and deploys the Gradle wrapper to the current directory.') {
gradleVersion = '2.1'
}
dependencies {
def cargoVersion = '1.4.5'
cargo "org.codehaus.cargo:cargo-core-uberjar:$cargoVersion",
"org.codehaus.cargo:cargo-ant:$cargoVersion"
}
cargo {
containerId = 'tomcat6x'
deployable {
file = project(':Frontend').war.archivePath
context = 'frontend'
}
deployable {
file = project(':Rest').war.archivePath
context = 'rest'
}
local {
homeDir = file('C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.35')
}
}
[cargoDeployRemote, cargoRunLocal]*.dependsOn project(':Frontend').war, project(':Rest').war
Rootproject common.gradle:
apply plugin: 'java'
apply plugin: 'maven'
String mavenGroupId = 'rootproject'
String mavenVersion = '1.0-SNAPSHOT'
sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
repositories {
mavenCentral();
// You may define additional repositories, or even remove "mavenCentral()".
// Read more about repositories here:
// http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:repositories
}
dependencies {
// Adding dependencies here will add the dependencies to each subproject.
testCompile group: 'junit', name: 'junit', version: '4.10'
}
String mavenArtifactId = name
group = mavenGroupId
version = mavenVersion
task sourcesJar(type: Jar, dependsOn: classes, description: 'Creates a jar from the source files.') {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives jar
archives sourcesJar
}
configure(install.repositories.mavenInstaller) {
pom.project {
groupId = mavenGroupId
artifactId = mavenArtifactId
version = mavenVersion
}
}
task createFolders(description: 'Creates the source folders if they do not exist.') doLast {
sourceSets*.allSource*.srcDirs*.each { File srcDir ->
if (!srcDir.isDirectory()) {
println "Creating source folder: ${srcDir}"
srcDir.mkdirs()
}
}
}
前端build.gradle:
apply plugin: 'war'
sourceCompatibility = 1.7
targetCompatibility = 1.7
if (!hasProperty('mainClass')) {
ext.mainClass = ''
}
sourceSets {
main {
java {
srcDir '/src/main/java'
}
resources {
srcDir '/src/main/java'
include '**/*.xml'
}
}
}
war {
archiveName = 'Frontend.war'
exclude('**/*.java,**/*.form')
}
dependencies {
providedCompile 'javax.servlet:servlet-api:2.5',
'javax.servlet:jsp-api:2.0'
compile project(':Data')
compile 'antlr:antlr:2.7.6'
}
看來您在混淆多個問題。 讓我看看是否可以根據我的理解給您答案。
您正在嘗試部署由兩個不同子項目創建的兩個WAR,這兩個子項目是Gradle多項目構建的一部分。 Gradle Cargo插件僅支持本地或遠程容器,因此我不確定為什么要提到嵌入式容器。 現在,假設我們要部署到本地安裝的Tomcat 6容器。
在以下Cargo插件配置中,我假設子項目具有項目路徑:frontend
和:rest
(它們可能與您不同)。 我將此配置放入根項目的構建腳本中。
cargo {
containerId = 'tomcat6x'
deployable {
file = project(':frontend').war.archivePath
context = 'frontend'
}
deployable {
file = project(':rest').war.archivePath
context = 'rest'
}
local {
homeDir = file('...')
}
}
[cargoDeployRemote, cargoRunLocal]*.dependsOn project(':frontend').war, project(':rest').war
我認為NetBeans與回答您的問題並不真正相關。 在IDE中,您可以簡單地調用相應的Gradle任務。 只要創建正確的項目依賴項,部署順序就無關緊要。 您可能還想在“使用Gradle進行Web應用程序部署”上觀看此視頻,以更好地了解今天可以在Gradle中完成的操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.