簡體   English   中英

Maven沒有將HTML正確地放入WAR

[英]Maven not putting HTML properly to WAR

我從Wicket的快速入門原型制作了新的Maven模塊。 Pom看起來像這樣:

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>keeper</groupId>
<artifactId>keeper</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
    <!-- TODO project name  -->
<name>quickstart</name>
<description></description>
<properties>
    <wicket.version>6.12.0</wicket.version>
    <jetty.version>7.6.13.v20130916</jetty.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
    <!--  WICKET DEPENDENCIES -->
    <dependency>
        <groupId>org.apache.wicket</groupId>
        <artifactId>wicket-core</artifactId>
        <version>${wicket.version}</version>
    </dependency>
    <!-- OPTIONAL DEPENDENCY
    <dependency>
        <groupId>org.apache.wicket</groupId>
        <artifactId>wicket-extensions</artifactId>
        <version>${wicket.version}</version>
    </dependency>
    -->

    <!-- LOGGING DEPENDENCIES - LOG4J -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.4</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>

    <!--  JUNIT DEPENDENCY FOR TESTING -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

    <!--  JETTY DEPENDENCIES FOR TESTING  -->
    <dependency>
        <groupId>org.eclipse.jetty.aggregate</groupId>
        <artifactId>jetty-all-server</artifactId>
        <version>${jetty.version}</version>
        <scope>provided</scope>
    </dependency>
</dependencies>
<build>
    <resources>
        <resource>
            <filtering>false</filtering>
            <directory>src/main/resources</directory>
        </resource>
        <resource>
            <filtering>false</filtering>
            <directory>src/main/java</directory>
            <includes>
                <include>**</include>
            </includes>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <filtering>false</filtering>
            <directory>src/test/resources</directory>
        </testResource>
        <testResource>
            <filtering>false</filtering>
            <directory>src/test/java</directory>
            <includes>
                <include>**</include>
            </includes>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </testResource>
    </testResources>
    <plugins>
        <plugin>
            <inherited>true</inherited>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <encoding>UTF-8</encoding>
                <showWarnings>true</showWarnings>
                <showDeprecation>true</showDeprecation>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.9</version>
            <configuration>
                <downloadSources>true</downloadSources>
            </configuration>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>Apache Nexus</id>
        <url>https://repository.apache.org/content/repositories/snapshots/</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
</project>

我的問題是Maven沒有將htML文件正確地放入WAR文件中。 如果我的HTML文件packeg位置是: com.company.project.HomePage.html但是,那個Maven會將這個文件放在WAR的classes文件夾中的com/company/project/ ,同時將它放在com.company.project目錄中(這是完整的名稱)。 因此,當我啟動Wicket的頁面時,會有一個例外:

Last cause: Can not determine Markup. Component is not yet connected to a parent. [Page class = pl.com.suadeo.keeperBrowser.HomePage, id = 2, render count = 1]

我試圖更改WebApplication配置中的位置並更改HTML位置,但是效果是相同的:

@Override
public void init()
{
    super.init();

    // add your configuration here
    this.getResourceSettings().getResourceFinders().add( new WebApplicationPath( this.getServletContext(), "pages" ) );
}

考慮到以上設置,HTML應該位於WARs / pages文件夾中(不在WEB-INF中)。 為什么Maven包裝有問題?

起初,我的HTML文件被毗鄰相應的Java類新(例如HomePage.java和HomePage.html在src.main.java.com.company.project )。 接下來,更改了Wicket的配置后,我嘗試將它們放在src.main.resources.pagessrc.main.webapp.pagessrc.main.webapp.WEB-INF.pages但沒有任何效果

我常見的放置文件的方法是使用默認的標記資源查找器。 因此,這意味着將標記文件放入源目錄。 這意味着代碼在src / main / java / com / company / project / MyPage.java中,而相關的標記在src / main / java / com / company / project / MyPage.html中。

將標記添加到JAR(也包括WAR)的Maven配置為:

src / main / resources / .java true src / main / java / .java

<testResources>
    <testResource>
        <directory>src/test/java</directory>
        <includes>
            <include>**</include>
        </includes>
        <excludes>
            <exclude>**/*.java</exclude>
        </excludes>
    </testResource>
    <testResource>
        <directory>src/test/resources</directory>
        <includes>
            <include>**</include>
        </includes>
        <excludes>
            <exclude>**/*.java</exclude>
        </excludes>
    </testResource>
</testResources>

...

我將HTML文件放在src/main/resources文件夾下,然后按照程序包層次結構進行操作。 您的情況是:

src/main/resources/comcompany/project/HomePage.html

因此,我將Java和html文件分開,但是Maven會在部署時自動將它們合並在一起(無需進一步配置)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM