简体   繁体   中英

Maven not putting HTML properly to WAR

I've made new maven module, from Wicket's quick start archetype. Pom looks like this:

<?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>

My problem is that Maven is not correcly putting htML files in WAR file. If my HTML file packeg location is: com.company.project.HomePage.html I though, that Maven will put this file in com/company/project/ inside WAR's classes folder, meanwhile its in com.company.project directory (that's full name). So when I start Wicket's page there's exception:

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]

I've tried to change location in WebApplication config and changing HTML location but effect is the same:

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

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

Considering above setup, HTMLs should be located in WARs /pages folder (not inside WEB-INF?). Why there's problem with maven packaging?

At first, my HTML files were located next to corresponding Java classess (for example HomePage.java and HomePage.html in src.main.java.com.company.project ). Next, after changing Wicket's config, I've tried to put them in src.main.resources.pages , src.main.webapp.pages and src.main.webapp.WEB-INF.pages but nothing worked

My common way how to put files is to use the default markup resource finder. So that means put markup files into source directories. It means the code is in src/main/java/com/company/project/MyPage.java and the associated markup is in src/main/java/com/company/project/MyPage.html.

The maven configuration to include the markup into JAR (also WAR) is:

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>

...

I put my HTML files under the src/main/resources folder and then following the package hierarchy. In your case would be:

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

So that, I have java and html files separated but Maven will merge them together automatically (no further configuration is needed) when deploying.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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