简体   繁体   English

Maven没有将HTML正确地放入WAR

[英]Maven not putting HTML properly to WAR

I've made new maven module, from Wicket's quick start archetype. 我从Wicket的快速入门原型制作了新的Maven模块。 Pom looks like this: 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>

My problem is that Maven is not correcly putting htML files in WAR file. 我的问题是Maven没有将htML文件正确地放入WAR文件中。 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). 如果我的HTML文件packeg位置是: com.company.project.HomePage.html但是,那个Maven会将这个文件放在WAR的classes文件夹中的com/company/project/ ,同时将它放在com.company.project目录中(这是完整的名称)。 So when I start Wicket's page there's exception: 因此,当我启动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]

I've tried to change location in WebApplication config and changing HTML location but effect is the same: 我试图更改WebApplication配置中的位置并更改HTML位置,但是效果是相同的:

@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?). 考虑到以上设置,HTML应该位于WARs / pages文件夹中(不在WEB-INF中)。 Why there's problem with maven packaging? 为什么Maven包装有问题?

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 ). 起初,我的HTML文件被毗邻相应的Java类新(例如HomePage.java和HomePage.html在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 接下来,更改了Wicket的配置后,我尝试将它们放在src.main.resources.pagessrc.main.webapp.pagessrc.main.webapp.WEB-INF.pages但没有任何效果

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. 这意味着代码在src / main / java / com / company / project / MyPage.java中,而相关的标记在src / main / java / com / company / project / MyPage.html中。

The maven configuration to include the markup into JAR (also WAR) is: 将标记添加到JAR(也包括WAR)的Maven配置为:

src/main/resources src / main / resources / .java true src/main/java / .java true src / main / java / .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. 我将HTML文件放在src/main/resources文件夹下,然后按照程序包层次结构进行操作。 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. 因此,我将Java和html文件分开,但是Maven会在部署时自动将它们合并在一起(无需进一步配置)。

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

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