title: How Spring boot recognize static resources in target/classes folder when build project?
body: <p>I'm trying to build the React app and include it in my spring boot as a static resource.</p>
  
  <p>I copied react build folder into <code>target/classes/public</code> of my spring boot project, using <code>maven-antrun-plugin</code>.</p>
  
  <p>I tried both name, <code>target/classes/public</code> and <code>target/classes/static</code>.</p>
  
  <p>This is my pj/target/classes structure after execute <code>$mvn package</code></p>
  
  <pre><code>C:\Users\tlatl\Desktop\pj1\target\classes&gt;tree /F
  OS 볼륨에 대한 폴더 경로의 목록입니다.
  볼륨 일련 번호는 722D-1A0E입니다.
  C:.
  │  application.properties
  │
  ├─com
  │  └─example
  │      └─demo
  │          │  DemoApplication.class
  │          │
  │          ├─controller
  │          │      Controller.class
  │          │      UrlRestController.class
  │          │
  │          ├─domain
  │          │      Url.class
  │          │
  │          ├─repository
  │          │      UrlRepository.class
  │          │
  │          └─service
  │                  UrlService.class
  │
  └─public
      │  asset-manifest.json
      │  favicon.ico
      │  index.html
      │  logo192.png
      │  logo512.png
      │  manifest.json
      │  precache-manifest.5260fb84a466ee86d0bc9ba13f9afc09.js
      │  robots.txt
      │  service-worker.js
      │
      └─static
          ├─css
          │      main.500ce7b4.chunk.css
          │      main.500ce7b4.chunk.css.map
          │
          └─js
                  2.c878f2b2.chunk.js
                  2.c878f2b2.chunk.js.LICENSE
                  2.c878f2b2.chunk.js.map
                  main.1b913fda.chunk.js
                  main.1b913fda.chunk.js.map
                  runtime-main.e1737718.js
                  runtime-main.e1737718.js.map
  
  </code></pre>
  
  <p>But after I execute the resulting jar file, localhost:8080 just shows a blank page.</p>
  
  <p>In the blog I referred, <a href="https://blogg.kantega.no/webapp-with-create-react-app-and-spring-boot/" rel="nofollow noreferrer">https://blogg.kantega.no/webapp-with-create-react-app-and-spring-boot/</a>, the writer said: </p>
  
  <blockquote>
    <p>Spring Boot applications can serve static content if you put it into the classes/public directory of the application jar file. </p>
    
    <p>Anything that's in the public directory on the classpath is served as a static resource by the default servlet, so you do not need to create an MVC controller for this. </p>
  </blockquote>
  
  <p>So I did not set any controller with the "/" path. Other rest APIs I set are working well through the URL.</p>
  
  <p>Why my spring boot does not show a static bundle in the <code>target/classes/public</code> folder? </p>
  
  <p>Below is my pom.xml file.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.2.2.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;demo&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;demo&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;node.version&gt;v12.3.1&lt;/node.version&gt;
          &lt;yarn.version&gt;v1.16.0&lt;/yarn.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;jstl&lt;/groupId&gt;
              &lt;artifactId&gt;jstl&lt;/artifactId&gt;
              &lt;version&gt;1.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt;
              &lt;artifactId&gt;tomcat-embed-jasper&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-mongodb&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
                      &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
  
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;com.github.eirslett&lt;/groupId&gt;
                  &lt;artifactId&gt;frontend-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;1.6&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;workingDirectory&gt;src/main/frontend&lt;/workingDirectory&gt;
                      &lt;installDirectory&gt;target&lt;/installDirectory&gt;
                  &lt;/configuration&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;install node and npm&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;install-node-and-npm&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;nodeVersion&gt;v8.9.4&lt;/nodeVersion&gt;
                              &lt;npmVersion&gt;5.6.0&lt;/npmVersion&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;id&gt;npm install&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;npm&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;arguments&gt;install&lt;/arguments&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;id&gt;npm run build&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;npm&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;arguments&gt;run build&lt;/arguments&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;phase&gt;generate-resources&lt;/phase&gt;
                          &lt;configuration&gt;
                              &lt;target&gt;
                                  &lt;copy todir="${project.build.directory}/classes/public"&gt;
                                      &lt;fileset dir="${project.basedir}/src/main/frontend/build"/&gt;
                                  &lt;/copy&gt;
                              &lt;/target&gt;
                          &lt;/configuration&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;run&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
  
  
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>