[英]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.pages
, src.main.webapp.pages
和src.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.