简体   繁体   中英

Spring boot JSF executable JAR can not find xhtml files

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM