2013-08-22 37 views
7

我下面一個Hello World Wicket應用程序的Java /檢票:編譯基本的Hello World與資源

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 

然而,當我編譯這一場戰爭的文件,並在碼頭裝載,我收到此錯誤,在瀏覽器中:

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) 

當我看在戰爭文件我注意到,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 fil e包含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> 
+3

爲什麼不使用http://wicket.apache.org/start/quickstart.html中的快速啓動發生器?然後,您可以從正在運行的應用程序中粘貼一個貼。至少你可以用你製作的pom.xml從快速入門中區分出pom.xml。 –

+0

謝謝,正如你所提到的那樣,我得到了解決方案。在下面發佈。 –

回答

17

解決方案如果你想在你的類的最佳實踐場所中使用你的HTML,那就是將它添加到你的pom的構建部分。

<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> 
+0

很好的解釋。爲什麼要停用src/main/resources'的過濾? – JimHawkins

1

你應該把你HelloWorld.html文件到文件夾src/main/webapp。這樣它將被包含在war文件中

+0

接受,你可以更具體的路徑? –

+0

更新了答案 – WeMakeSoftware

+0

毫無疑問,這會起作用,但David Williams的回答更好,因爲它遵循Wicket最佳實踐。 – iluwatar