gpt4 book ai didi

java - webapp资源进入目标

转载 作者:行者123 更新时间:2023-12-02 13:22:56 28 4
gpt4 key购买 nike

网络资源不会被复制到 target/classes 文件夹,因此不在 target/${finalName}/WEB-INF/classes 文件夹中。

目前 mvn clean install 的输出:

目标/类/(src/main/java)

但是我也想得到:

目标/类/(src/main/webapp)

pom:

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>StrategicTestArchitecture</groupId>
<artifactId>STATestAPI</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<!-- <configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warSourceDirectory>WebContent</warSourceDirectory>
<webResouces>
<resource>
<directory>src/main/webapp</directory>
<targetPath>WEB-INF/classes</targetPath>
</resource>
<resource>
<directory>${baseDir}/src/main/webapp</directory>
<targetPath>target/${finalName}/WEB-INF</targetPath>
</resource>
</webResouces>
</configuration> -->
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>Spring.properties</include>
</includes>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>staging</id>
<activation>
<property>
<name>environment</name>
<value>staging</value>
</property>
</activation>
<properties>
<hibernate.dialect>org.hibernate.dialect.Oracle10gDialect</hibernate.dialect>
<hibernate.show_sql>true</hibernate.show_sql>
<hibernate.url>myoracleurl</hibernate.url>
<DriverClassName>oracle.jdbc.driver.OracleDriver</DriverClassName>
</properties>
</profile>
<profile>
<id>alpha</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<hibernate.dialect>org.hibernate.dialect.Oracle10gDialect</hibernate.dialect>
<hibernate.show_sql>true</hibernate.show_sql>
<hibernate.url>myoracleurl</hibernate.url>
<DriverClassName>oracle.jdbc.driver.OracleDriver</DriverClassName>
</properties>
</profile>
</profiles>
<properties>
<!-- Generic properties -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>

<!-- SPRING & HIBERNATE / JPA -->
<spring.version>4.3.5.RELEASE</spring.version>
<hibernate.version>5.2.5.Final</hibernate.version>

</properties>
<dependencies>
<dependency>
<groupId>StrategicTestArchitecture</groupId>
<artifactId>Commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

任何人都可以解释为什么这些文件没有被复制到输出目录中吗?

最佳答案

正如 Steve C 所提到的,Web 资源不需要位于类路径上,因此 Web 配置可以留空。这会将 src/main/webapp 目录中的所有内容复制到 war 文件的根目录中。

就我而言,我们有一个名为 resources 的文件夹,位于 src/main/webapp/resources ,其中包含我们的 html/css/js

作为 spring 配置中的引用,registryhandler 可以这样修改:

public void addResourceHandlers(ResourceHandlerRegistry registry){
registry.addResourceHandler("/resources/**").addResourceLocations("resources/");
}

关于java - webapp资源进入目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43497150/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com