简体   繁体   English

maven war插件配置错误

[英]wrong configuration of maven war plugin

I'm a basic maven user and I'm trying to copy the resources folder into the war file created by maven.我是基本的 maven 用户,我正在尝试将资源文件夹复制到由 maven 创建的 war 文件中。 I need to do this in order to be able to import css files into my jsp files.我需要这样做才能将 ZC7A62​​8CBA22E28EB17B5F5C6AE2A266AZ 文件导入到我的 jsp 文件中。 These are the relevant parts of my configuration files:这些是我的配置文件的相关部分:

servlet.xml servlet.xml

<mvc:resources location="/resources" mapping="/resources/**"></mvc:resources>

pom.xml pom.xml

<plugins>
        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.3.2</version>
        <configuration>
        <web-resources>
        <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>**/*.css</include>
        </includes>
        </resource>
        </web-resources>
        <outputDirectory>../../tomcat/webapps</outputDirectory> 
        </configuration>
      </plugin>
    </plugins>

jsp file: jsp文件:

<header>
    <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/style.css">
</header>

resources structure:资源结构:

  • resources资源
    -- css -- ZC7A62​​8CBA22E28EB17B5F5C6AE2A266AZ
    style.css样式.ZC7A62​​8CBA22E28EB17B5F5C6AE2A266AZ

I've spotted that the css folder is actually copied into the classes folder, but even changing the import path into the jsp file I'm not able to correctly load the css file.我发现 ZC7A62​​8CBA22E28EB17B5F5C6AE2A266AZ 文件夹实际上已复制到 classes 文件夹中,但即使将导入路径更改为 jsp 文件,我也无法正确加载 ZC7A62​​8CBA22E28EB17B5F5C6AE2A266AZ 文件。 To launch the install I simply issue: mvn clean install要启动安装,我只需发出: mvn clean install

The default configuration of the war plugin will copy your resources into the root of your WAR. war 插件的默认配置会将您的资源复制到 WAR 的根目录中。 I recommend just leaving the plugin without any additional configuration, and adjusting your mapping.我建议只保留插件而不进行任何其他配置,并调整您的映射。

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.2</version>
  </plugin>

This will put your css folder into /css in your war, then you just configure your mapping as such.这会将您的css文件夹放入您的战争中的/css中,然后您只需像这样配置您的映射。

<mvc:resources location="/css" mapping="/resources/css"></mvc:resources>

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

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