2017-04-19 97 views
-1

網絡資源不會被複制到目標/類文件夾,因此不會被複制到target/$ {finalName}/WEB-INF/classes文件夾中。將webapp資源轉換爲目標

此刻從mvn clean install輸出:

target/classes/(src/main/java)

但是我也試圖讓:

target/classes/(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> 

任何人都可以擺脫一些光至於爲什麼這些文件沒有被複制到輸出目錄?

+3

你不需要任何配置。 'mvn clean install'默認會從'src/main/java','src/main/resources'和'src/main/webapp'建立一個正確結構的WAR文件。 –

+0

刪除配置沒有改變輸出:( src/main/webapp下的所有東西都在war和target/$ finalName的根目錄下,但不在我們需要它們的目標/類中:/ – Alex

+0

爲什麼你想要你的webapp資源在'target/classes'? –

回答

0

正如Steve C所述,Web資源不需要放在類路徑中,因此Web配置可以留空。這會將src/main/webapp目錄中的所有內容複製到war文件的根目錄中。

在我的情況下,我們必須位於src/main/webapp/resources一個文件夾,名爲資源,這包含了我們的HTML/CSS/JS

對於Spring配置的registryhandler參考可以修改爲這樣:

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