2

I have the problem that my spring boot JSF application works in IntelliJ but not as an executable JAR. The application starts up without a problem, but it can not resolve the xhtml templates. In IntelliJ everything works as expected.

I found this question regarding a similar problem. I oriented at the file structure and can not see any difference.

Spring Boot JSF packaging as a JAR

My maven file structure:

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

So when I start the Spring Boot application it will pick up at target/classes

The structure there is:

 target
   | classes
        | META-INF
             | resources
                  | index.xhtml
             | faces-config.xml

In the created executable JAR the structure is

  org
  BOOT-INF
     | lib
     | classes
         | de ...
  META-INF
     | resources
         | index.xhtml
     | faces-config.xml

As far as I understand various sites and answers, this should be the correct structure in the jar to pick up the xhtml files. But it does not work for me. I copied out of desperation the META-INF directory into the BOOT-INF/classes directory and in another iteration just the resources directory from META-INFO into BOOT-INF/classes. But nothing works. It can still not resolve the xhtml files.

How should be the structure of my jar file?

Marc
  • 271
  • 2
  • 4
  • 14

1 Answers1

4

I had the same problem with packaging JSF pages to executable jar. There are other SO topics (aren't helpful for me) related to the issue:

I ended up converting the project to war. Hopefully spring-boot-maven-plugin supports executable wars.

  1. I specified <packaging>war</packaging> in pom.xml.
  2. I had to remove <layers><enabled>true</enabled></layers> from spring-boot-maven-plugin configuration.

War project structure:

 pom.xml
 src
 └── main
     ├── java
     │   └── xxx
     ├── resources
     │   ├── application.yml
     └── webapp
         ├── xxx.xhtml
         └── WEB-INF
             └── faces-config.xml

spring-boot-maven-plugin runs its repackage. Unzipped war structure:

├── META-INF
│   ├── MANIFEST.MF
│   └── maven
│       └── com.fusion
│           └── jsf-application
│               ├── pom.properties
│               └── pom.xml
├── org
│   └── springframework
│       └── boot
│           └── loader
│               ... spring classes here
│               └── WarLauncher.class
├── xxx.xhtml
└── WEB-INF
    ├── classes
    │   ... project classes 
    ├── faces-config.xml
    └── lib
        ... all the libs


It's possible to run the war using java -jar jsf-application.war.

Petr Aleksandrov
  • 1,434
  • 9
  • 24
  • 1
    Excellent answer! I have spent days investigating this and ended up at exactly this. However, it would be nice if xxx.xhtml files could be placed under WEB-INF as well. This is possible for jsp files with application.properties: spring.mvc.view.prefix = /WEB-INF/ But for JSF files (xxx.xhtml) it does not seem to work... – Barsk Oct 07 '21 at 10:25
  • Kindly share a working sample for spring boot 2+JSF2 with WAR deployment option. I am getting errors like javax.faces.view.facelets.TagAttributeException: locale="#{languageBean.getLanguage()}" Attribute did not evaluate to a String or Locale: null....Seems @ManagedBean are not be recognized or loaded. Any idea why? – Jacob Jun 29 '22 at 14:28