0

I have to provide static .js files through a JAR project. For this I created a JAR(using MAVEN) which looks like:

parent
|--com
|--META-INF
|--webapp
   |--resources
      |--js
         |--myjs.js

Now, I added this JAR to my parent spring-boot project and in one of the JSPs added

<script src="resources/js/myjs.js"></script>

This gives me a 404 error.

My conclusion: Either the boot project does not merge webapp folders from JARs into its own webapp or I am accessing the file incorrectly.

These questions did not help(cannot change WebMvcConfigurerAdapter and java code is strictly not allowed ):

SpringBoot - accessing a file inside resources folder
Serve static resources within jar files by Spring boot

Usually, such things are handled using overlays but that would be and overkill for a simple use case.

YetAnotherBot
  • 1,937
  • 2
  • 25
  • 32

1 Answers1

0

Your webapp folder is secured folder.You cannot access files directly inside it. You need to permit all your incoming requests of js and other static files as following:-

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
         http
            .authorizeRequests()
            .antMatchers("/", "/js/**", "/css/**").permitAll();
        http.csrf().disable();
    }
}
Jaspreet Jolly
  • 1,235
  • 11
  • 26