3

I am trying to create a spring boot app with jsf and gradle.

So far, during development everything was fine. When I wanted to run my App I just typed gradle bootRun, the app started and I was able to access it under 'localhost'.

Now I am at a point of time, where I want to deploy the app, therefore I run the command 'gradle clean distTar' which creates the tar file to deploy.

After running the generated script and accessing my app via Browser I just get an 404 with the message.

index.xhtml Not Found in ExternalContext as a Resource

Also in the jar file, there aren't any html files included. I included them in the jar with the command

from ("${projectDir}/src/main/webapp/"){
    into('resources')
}

Referring to https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot this files should be accessible. But still nothing changed.

Does anyone else have a clue? What am I doing wrong?

BR

questionaire
  • 2,475
  • 2
  • 14
  • 28
  • Also adding a folder named resources containing all the files, to classpath, doesnt help... – questionaire Apr 06 '15 at 06:20
  • Does no one have a clue or is my question that bad? This really drives me crazy... – questionaire Apr 08 '15 at 19:57
  • BTW: For the sakeness of completion, I stopped investigating this issue. In the following repository I uploaded an example Project: https://github.com/MALPI/PrimefacesOnSpringBoot/ There is also an ongoing discussion about this problem https://github.com/MALPI/PrimefacesOnSpringBoot/issues/1 for me it seemed like the DispatcherServlet is reinitiaized due to some SpringMVC autoconfig Magic. – questionaire Jun 15 '15 at 12:30

3 Answers3

1

I've been also struggling with this thing and finally managed to come up with a working solution.

As stated in: https://stackoverflow.com/a/9473487/4250114 if you use Servlet3.x (and you probably are with SpringBoot).

For me structure in maven looks like below worked:

 src 
   |-main
     | ...
     |-resources
        |-META-INF
           |-faces-config.xml
           |-resources
               |-test.xhtml

So in jar it should be:

|-META-INF
    |-faces-config.xml
    |-resources
        |-test.xhtml
Community
  • 1
  • 1
Dawid Wysakowicz
  • 3,402
  • 17
  • 33
  • Pls see my last comment, since I can't proof your answer as propper solution currently, I cannot mark this issue as solved. But thanks anyway! I will try this is out the next weeks. – questionaire Jun 15 '15 at 12:32
  • OK. I just added the answer cause i spent so much time looking for a solution, so maybe this answer will save somebody some time. – Dawid Wysakowicz Jun 15 '15 at 12:36
  • 1
    Hopefully! I will try it, as soon as I have time. Currently I switched from springBoot to deploying a *.war file on a tomcat7. – questionaire Jun 15 '15 at 12:57
0

Follow the given structure to create fat jar :

Demo
└── src
|    ├── main
|    │   ├── java
|    │   │     └── org
|    │   │          └── demo
|    │   │                └── App.java
|    │   └── resources
|    |       |
|    │       └── application.properties
|    |       |
|    |       └── META-INF
|    |       |        └── resources
|    |       |                 └── jsp
|    |       └── static
|    |              └── css
|    |              └── js
|    |    
|    └── test
|         └── java
|               └── org
|                    └── demo
|                          └── App.java  
├──── pom.xml
Riddhi Gohil
  • 1,758
  • 17
  • 17
0

Based on information from https://github.com/spring-projects/spring-boot/issues/8299 and also based on the output from SpringBoot+Jetty

2018-01-15 15:57:03 [main] INFO  o.j.jetty.JsfJettyServerCustomizer - Setting Jetty classLoader to META-INF/resources directory

I used this in my Gradle file:

jar {
    baseName = 'csm'
    version = "0.0.1-SNAPSHOT"

    from("build/docs/"){
        into("generated/docs/")
    }
    from("src/main/resources/"){
        include("**")
    }
    // JSF and SpringBoot and Jetty require all webapp files to be in a very particular location.
    // See: https://github.com/spring-projects/spring-boot/issues/8299
    from ("${projectDir}/src/main/webapp/"){
        into('META-INF/resources')
    }
}

/BOOT-INF
/META-INF/
   /resources/
      /WEB-INF/
         web.xml
      index.jsf
      blah.xhtml
cs94njw
  • 535
  • 5
  • 12