Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup a Gradle build for a JSF2 application to be hosted by JBoss AS 7.1?

At this moment I have a build.gradle file that successfuly compiles and tests (using JUnit4) a very very simple java project.

My next step is to add JSF2 support (in order to have a web JSF2 application) to this build. The idea is to host the application in my local JBoss 7.1 container. Now things became a little fuzzy to me.

What I did was to add JSF2 support to my buid by adding some dependencies, so the dependencies block is like this now:

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'
}

First strange thing that I noticed is that after refreshing the project with Gradle (by using Gradle > Refresh All menu), JBoss is unable to see it. I noticed that (it seems) Gradle disabled the use of facets in the project. If I manually activate facets and set the runtime to JBoss 7.1, then I'll be able to add it to JBoss (but I would prefer not to have to do it manually anymore).

After adding it to JBoss I can run the server, and the log says the module corresponding to my web application was correctly loaded by JBoss, however when I type it's url in a browser, the server responds with HTTP status 404.

In src/main/webapp I have the simple index.html file (shown below), so what I expected was just to see it's content in the browser, but that does not happen.

<html>
<body>
<h1>Hello world!</h1>
</body>
</html>

What am I missing?

like image 417
AlexSC Avatar asked Dec 05 '14 14:12

AlexSC


1 Answers

After some study I finally understood that things were much simpler. That I was missing to understand is that I was using the wrong Gradle plug-in. I had to replace eclipse plug-in by eclipse-wtp and then specify which facets and runtime I wanted to use in my application.

The final build.gradle file is below:

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'
}

I hope this may help some other people!

like image 60
AlexSC Avatar answered Oct 22 '22 23:10

AlexSC