简体   繁体   English

Spring boot:在类路径文件夹(类)之外的自定义文件夹中添加静态网页(Angular)

[英]Spring boot : Add static web page (Angular) in a custom folder outside classpath folder (classes)

How would I place the static contents in a WAR Archive.我将如何将静态内容放置在 WAR 存档中。
I have tried placing them inside the classes folder and works fine, but to make the cleaner I am asked to put it outside the WEB-INF, in a custom folder.我尝试将它们放在 classes 文件夹中并且工作正常,但是为了使我更干净,我被要求将它放在 WEB-INF 之外的自定义文件夹中。 I was able to do that and make it work by setting the welcome page in web.xml我能够做到这一点并通过在 web.xml 中设置欢迎页面来使其工作

<welcome-page>'./app/index.html'</welcome-page>

But the issue is that I don't want 'app' to appear in my URL, when the pages were kept inside classes/static the index.html appeared in root(localhost:8080), but putting the pages in custom folder URL changed to - localhost:8080/app但问题是我不希望“app”出现在我的 URL 中,当页面保存在classes/static 中时,index.html 出现在 root(localhost:8080) 中,但将页面放在自定义文件夹 URL 中到 - 本地主机:8080/应用程序
Is there any way to keep the pages in a custom folder and still get the index page and its dependencies from root URL.有什么方法可以将页面保留在自定义文件夹中,并且仍然从根 URL 获取索引页面及其依赖项。

Either you place your resources under "src/main/webapp", these will be copied to the root of your WAR.要么将资源放在“src/main/webapp”下,这些资源将被复制到 WAR 的根目录。 If you need more flexibility, maybe the maven-war-plugin:如果您需要更大的灵活性,可以使用 maven-war-plugin:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>3.2.0</version>
    <configuration>
      <webResources>
        <resource>
          <directory>${project.basedir}/mycustomdir</directory>
          <targetPath>somewhere</targetPath>
        </resource>
      </webResources>
    </configuration>
</plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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