JMIX 2.0 fatjar build contains reference to style (error)

I get the following error when trying to build a fatjar for testing.

When running java -jar .jar:

Caused by: java.util.concurrent.CompletionException: java.lang.IllegalStateException:

Failed to find the following css files in the node_modules or /Users/mariussnyman/IdeaProjects/accur82/frontend directory tree:
- ./styles/grid-tree-toggle-adjust.css
Check that they exist or are installed. If you use a custom directory for your resource files instead of the default frontend folder then make sure it’s correctly configured (e.g. set ‘vaadin.frontend.frontend.folder’ property)

====
After running the gradle jobs for Vaadin to vaadinPrepareFrontend and vaadinBuildFrontend I found the file in the ./frontend/generated/jar-resources/styles , but that gets deleted automatically when building with bootJar Gradle script.

I also tried setting the frontend path in application.properties:
vaadin.frontend.frontend.folder=${user.dir}/frontend/generated/jar-resources

Hope someone can help.

Regards
Marius

Have you specified -Pvaadin.productionMode=true option when building the JAR?
See Basic Deployment :: Jmix Documentation

When I try the gradle cli command:
./gradlew -Pvaadin.productionMode=true bootJar

Welcome to Gradle 8.0.2!

Here are the highlights of this release:

  • Improvements to the Kotlin DSL
  • Fine-grained parallelism from the first build with configuration cache
  • Configurable Gradle user home cache cleanup

For more details see Gradle 8.0.2 Release Notes

Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details

Task :vaadinBuildFrontend FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:vaadinBuildFrontend’.

Vite process exited with non-zero exit code.
Stderr: 'vite v4.1.5 building for production…
transforming…
✓ 129 modules transformed.
warnings when minifying css:
▲ [WARNING] Unexpected “{” [css-syntax-error]

  <stdin>:1:0:
    1 │ {
      ╵ ^

▲ [WARNING] Expected identifier but found ““name”” [css-syntax-error]

  <stdin>:2:2:
    2 │   "name": "Flowable",
      ╵   ~~~~~~

warnings when minifying css:
▲ [WARNING] Unexpected “{” [css-syntax-error]

  <stdin>:1:0:
    1 │ {
      ╵ ^

▲ [WARNING] Expected identifier but found ““name”” [css-syntax-error]

  <stdin>:2:4:
    2 │     "name": "Jmix BPM",
      ╵     ~~~~~~

[vite:css] [postcss] postcss-import: /Users/mariussnyman/IdeaProjects/accur82/frontend/themes/accur82/accur82.css:78:1: Unexpected }
file: /Users/mariussnyman/IdeaProjects/accur82/frontend/themes/accur82/styles.css?used&inline:78:1
error during build:
CssSyntaxError: [postcss] postcss-import: /Users/mariussnyman/IdeaProjects/accur82/frontend/themes/accur82/accur82.css:78:1: Unexpected }
at Input.error (/Users/mariussnyman/IdeaProjects/accur82/node_modules/postcss/lib/input.js:106:16)
at Parser.unexpectedClose (/Users/mariussnyman/IdeaProjects/accur82/node_modules/postcss/lib/parser.js:579:22)
at Parser.end (/Users/mariussnyman/IdeaProjects/accur82/node_modules/postcss/lib/parser.js:325:12)
at Parser.parse (/Users/mariussnyman/IdeaProjects/accur82/node_modules/postcss/lib/parser.js:448:16)
at parse (/Users/mariussnyman/IdeaProjects/accur82/node_modules/postcss/lib/parse.js:11:12)
at new LazyResult (/Users/mariussnyman/IdeaProjects/accur82/node_modules/postcss/lib/lazy-result.js:133:16)
at Processor.process (/Users/mariussnyman/IdeaProjects/accur82/node_modules/postcss/lib/processor.js:53:14)
at runPostcss (file:///Users/mariussnyman/IdeaProjects/accur82/node_modules/vite/dist/node/chunks/dep-53dc1ef4.js:332:6)
at processContent (file:///Users/mariussnyman/IdeaProjects/accur82/node_modules/vite/dist/node/chunks/dep-53dc1ef4.js:326:10)
at file:///Users/mariussnyman/IdeaProjects/accur82/node_modules/vite/dist/node/chunks/dep-53dc1ef4.js:912:20

  • Try:

Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.

BUILD FAILED in 30s
6 actionable tasks: 4 executed, 2 up-to-date

I also discovered an extra “}” in my custom css which caused a problem.

Remaining issue seems to be:
java.lang.IllegalStateException:

Failed to find the following css files in the node_modules or /Users/mariussnyman/IdeaProjects/accur82/frontend directory tree:
- ./src/bpmn-modeler/bpmn-viewer.css
- ./styles/grid-tree-toggle-adjust.css
- ./styles/modeler-properties-style.css
Check that they exist or are installed. If you use a custom directory for your resource files instead of the default frontend folder then make sure it’s correctly configured (e.g. set ‘vaadin.frontend.frontend.folder’ property)

At what moment do you get this exception?
When running gradlew -Pvaadin.productionMode=true bootJar ?

1.) This error occurs when running the UI based option to build bootjar. (default settings before adding -Pvaadin.productionMode=true)

2.) ./gradlew -Pvaadin.productionMode=true bootJar
produces a running fatjar where there seems to be a problem with the path to load images, but gets the styling right. I am trying to understand what causes this.

The error was the same for UI build and cli build until pnpm was installed I think

So the error has gone after you manually installed pnpm?

yes, it works, but it relies on a production build flag as well. I presently have a logo on the login view, which shows during development, but when building the fatjar it no longer shows.

My reference in the viewlayout XML is:

Is there a best practice for this?

<image resource="./themes/accur82/images/goldlogo.svg" height="25%" />

Hello!

Is the goldlogo.svg placed under META-INF/resources folder? Documentation image::Resources.

I’ve tried to reproduce the problem but without success. LoginView shows the specified image resource.

Thanks for your response.

I think I understand the problem now.

Once I have logged in I can access /images/goldlogo.svg, otherwise I get redirected to the login view.

/images (in code at META-INF/resources/images) is not anonymously available on the login screen. How can I make it anonymously accessible please?

The same problem was was resolved here: Static resources problem: - #9.

You should enable requests by matcher, for instance:

@Configuration
public class MySecurityConfiguration {

    @Bean
    @Order(JmixSecurityFilterChainOrder.FLOWUI - 10)
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http.securityMatcher("/themes/**")
                .authorizeHttpRequests((authorize) -> authorize.requestMatchers("/themes/**").permitAll());
        return http.build();
    }
}

1 Like

Thanks it works, but I guess it would make sense to provide this by default when generating a new project, as before like on v.1.

1 Like

Yes, I’ve created an issue: Is not possible to get static resources from LoginView · Issue #2149 · jmix-framework/jmix · GitHub

1 Like