8

我正在关注这个 Hello World Wicket 应用程序的示例

https://www.ibm.com/developerworks/web/library/wa-aj-wicket/

特别是我把HelloWorld.html我的源目录放在HelloWorld.java.

我的文件结构如下所示:

$ tree
.
├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   │   └── com
│   │   │       └── example
│   │   │           └── wicket
│   │   │               ├── HelloWorld.html
│   │   │               ├── HelloWorld.java
│   │   │               └── HelloWorldApplication.java
│   │   ├── resources
│   │   └── webapp
│   │       └── WEB-INF
│   │           └── web.xml
│   └── test
│       └── java
└── wicketTest.iml 

但是,当我将其编译为 war 文件并在 Jetty 中加载时,我在浏览器中收到此错误:

Unexpected RuntimeException

Last cause: Can not determine Markup. Component is not yet connected to a parent. [Page class = com.example.wicket.HelloWorld, id = 4, render count = 1]

Stacktrace

Root cause:

org.apache.wicket.markup.MarkupNotFoundException: Can not determine Markup. Component is not yet connected to a parent. [Page class = com.example.wicket.HelloWorld, id = 4, render count = 1]
     at org.apache.wicket.Component.getMarkup(Component.java:737)
     at org.apache.wicket.Component.internalRender(Component.java:2344)
     at org.apache.wicket.Component.render(Component.java:2307)
     at org.apache.wicket.Page.renderPage(Page.java:1010) 

当我查看 war 文件时,我注意到缺少 html 文件:

$ tar tvf target/wicketTest-1.0-SNAPSHOT.war
drwxrwxrwx  0 0      0           0 Aug 22 14:50 META-INF/
-rwxrwxrwx  0 0      0         128 Aug 22 14:50 META-INF/MANIFEST.MF
drwxrwxrwx  0 0      0           0 Aug 22 14:50 WEB-INF/
drwxrwxrwx  0 0      0           0 Aug 22 14:50 WEB-INF/classes/
drwxrwxrwx  0 0      0           0 Aug 22 14:50 WEB-INF/classes/com/
drwxrwxrwx  0 0      0           0 Aug 22 14:50 WEB-INF/classes/com/example/
drwxrwxrwx  0 0      0           0 Aug 22 14:50 WEB-INF/classes/com/example/wicket/
drwxrwxrwx  0 0      0           0 Aug 22 14:50 WEB-INF/lib/
-rwxrwxrwx  0 0      0         608 Aug 22 14:50 WEB-INF/classes/com/example/wicket/HelloWorld.class
-rwxrwxrwx  0 0      0         551 Aug 22 14:50 WEB-INF/classes/com/example/wicket/HelloWorldApplication.class
-rwxrwxrwx  0 0      0       25962 Aug 21 16:07 WEB-INF/lib/slf4j-api-1.6.4.jar
-rwxrwxrwx  0 0      0     2126440 Aug 21 16:07 WEB-INF/lib/wicket-core-6.10.0.jar
-rwxrwxrwx  0 0      0       86671 Aug 21 16:07 WEB-INF/lib/wicket-request-6.10.0.jar
-rwxrwxrwx  0 0      0      415858 Aug 21 16:07 WEB-INF/lib/wicket-util-6.10.0.jar
-rwxrwxrwx  0 0      0         690 Aug 22 13:22 WEB-INF/web.xml
drwxrwxrwx  0 0      0           0 Aug 22 14:50 META-INF/maven/
drwxrwxrwx  0 0      0           0 Aug 22 14:50 META-INF/maven/wicketTest/
drwxrwxrwx  0 0      0           0 Aug 22 14:50 META-INF/maven/wicketTest/wicketTest/
-rwxrwxrwx  0 0      0         675 Aug 22 08:52 META-INF/maven/wicketTest/wicketTest/pom.xml
-rwxrwxrwx  0 0      0         112 Aug 22 14:50 META-INF/maven/wicketTest/wicketTest/pom.properties

如何在我的 POM 文件中指定包含 html 文件?

我现在的 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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>wicketTest</groupId>
    <artifactId>wicketTest</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>org.apache.wicket</groupId>
            <artifactId>wicket-core</artifactId>
            <version>6.10.0</version>
        </dependency>
    </dependencies>
</project>
4

3 回答 3

20

解决方案,如果您希望您的 HTML 在 wicket 最佳实践位置(与您的类)是添加到您的 pom.xml 的构建部分。

<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>
</build>
</project>
于 2013-08-22T23:49:39.997 回答
0

您应该将HelloWorld.html文件放入src/main/webapp文件夹中。这样它将被包含在war文件中

于 2013-08-22T21:56:15.207 回答
0

如果使用 Maven,请参阅 David Williams 的回答。如果使用 Gradle,请参阅此答案。

在您的文件中包含以下内容build.gradle

sourceSets {
    main {
        resources {
            srcDirs += ['src/main/java']
            includes = ["**"]
            // or specifically: includes = ["**/*.html"]
        }
    }
}

这可确保将 HTML 文件添加到 WAR 文件中。

于 2020-02-26T14:25:47.957 回答