[英]How to setup a build in Gradle to not deploy JUnit test cases to JBoss AS 7.1
[英]How to setup a Gradle build for a JSF2 application to be hosted by JBoss AS 7.1?
此時我有一個build.gradle
文件,它成功編譯並測試(使用JUnit4)一個非常簡單的java項目。
我的下一步是為此構建添加JSF2支持(為了擁有Web JSF2應用程序)。 我的想法是在我的本地JBoss 7.1容器中托管應用程序。 現在事情變得有點模糊了。
我所做的是通過添加一些依賴項來為我的buid添加JSF2支持,所以dependencies
塊現在是這樣的:
dependencies {
compile 'org.jboss.weld.se:weld-se-core:'+weldVersion
compile 'br.gov.frameworkdemoiselle:demoiselle-core:'+demoiselleVersion
compile 'br.gov.frameworkdemoiselle:demoiselle-jsf:'+demoiselleVersion
runtime 'javax.servlet:javax.servlet-api:3.1.0'
runtime 'javax.enterprise:cdi-api:1.0-SP1'
runtime 'org.jboss.weld.servlet:weld-servlet:'+weldVersion
runtime 'com.sun.faces:jsf-api:2.2.8-02'
runtime 'org.slf4j:slf4j-log4j12:1.7.7'
testCompile 'junit:junit:4.11'
testCompile 'org.jboss.arquillian.junit:arquillian-junit-container:'+arquillianVersion
testCompile 'br.gov.frameworkdemoiselle.component:demoiselle-junit:2.3.1'
}
我注意到的第一個奇怪的事情是,在使用Gradle > Refresh All
項目后(通過使用Gradle > Refresh All
菜單),JBoss無法看到它。 我注意到(似乎)Gradle禁用了項目中facet的使用。 如果我手動激活facets並將運行時設置為JBoss 7.1,那么我將能夠將其添加到JBoss(但我不想再手動執行)。
將它添加到JBoss后我可以運行服務器,日志說JBoss正確加載了與我的Web應用程序對應的模塊,但是當我在瀏覽器中輸入它的url時,服務器以HTTP狀態404響應。
在src/main/webapp
我有簡單的index.html
文件(如下所示),所以我所期望的只是在瀏覽器中看到它的內容,但這不會發生。
<html>
<body>
<h1>Hello world!</h1>
</body>
</html>
我錯過了什么?
經過一番研究,我終於明白事情要簡單得多。 我不理解的是我使用了錯誤的Gradle插件。 我不得不用eclipse-wtp
替換eclipse
插件,然后指定我想在我的應用程序中使用哪些方面和運行時。
最終的build.gradle文件如下:
apply plugin: 'java'
apply plugin: 'eclipse-wtp' // The correct plug-in!
apply plugin: 'application'
apply plugin: 'war'
sourceCompatibility = 1.7
targetCompatibility = 1.7
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
def hibernateVersion = "4.3.7.Final"
def weldVersion = "1.1.27.Final"//"2.2.7.Final" Demoiselle 2.4.1 não é compatível com Weld 2
def demoiselleVersion = "2.4.1"
def arquillianVersion = "1.1.5.Final"
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
runtime 'javax.servlet:javax.servlet-api:3.1.0'
runtime 'javax.enterprise:cdi-api:1.0-SP1'
runtime 'org.jboss:jandex:1.2.2.Final'
}
eclipse {
wtp {
facet {
facet name: "java", version: "1.7" // Java version
facet name: "jst.web", version: "3.0" // Dynamic Web Application
facet name: "jst.jsf", version: "2.2" // Java Server Faces
facet name: "wst.jsdt.web", version: "1.0" // JavaScript
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2.1'
}
我希望這可以幫助其他人!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.