如何为JBoss AS 7.1托管的JSF2应用程序设置Gradle构建?

Ale*_*xSC 6 java jboss gradle jsf-2 gradle-eclipse

此时我有一个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'
}
Run Code Online (Sandbox Code Playgroud)

我注意到的第一个奇怪的事情是,在用Gradle刷新项目后(通过使用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>
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

Ale*_*xSC 5

经过一番研究,我终于明白事情要简单得多.我不理解的是我使用了错误的Gradle插件.我不得不替换eclipse插件eclipse-wtp,然后指定我想在我的应用程序中使用哪些方面和运行时.

最终的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'
}
Run Code Online (Sandbox Code Playgroud)

我希望这可以帮助其他人!