我已经制作了新的maven模块,来自Wicket的快速启动原型。 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会将此文件放在com/company/project/
内的WAR的classes文件夹中,同时放在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 classess旁边(例如src.main.java.com.company.project
中的HomePage.java和HomePage.html)。接下来,在更改Wicket的配置后,我尝试将它们放入src.main.resources.pages
,src.main.webapp.pages
和src.main.webapp.WEB-INF.pages
,但没有任何效果
答案 0 :(得分:1)
我放置文件的常用方法是使用默认的标记资源查找器。这意味着将标记文件放入源目录中。这意味着代码位于src / main / java / com / company / project / MyPage.java中,关联的标记位于src / main / java / com / company / project / MyPage.html中。
将标记包含到JAR(也是WAR)中的maven配置是:
的src / main /资源 的 强> / 的.java 真正 的src /主/ 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>
...
答案 1 :(得分:0)
我将我的HTML文件放在src/main/resources
文件夹下,然后按照包层次结构。在你的情况下将是:
src/main/resources/comcompany/project/HomePage.html
因此,我将java和html文件分开,但Maven会在部署时自动将它们合并在一起(不需要进一步配置)。