gpt4 book ai didi

java - Maven 未将 HTML 正确放入 WAR

转载 作者:行者123 更新时间:2023-12-01 13:50:06 29 4
gpt4 key购买 nike

我根据 Wicket 的快速启动原型(prototype)制作了新的 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 类中的 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 类旁边(例如 src.main.java.com.company.project 中的 HomePage.java 和 HomePage.html)。接下来,更改 Wicket 的配置后,我尝试将它们放入 src.main.resources.pagessrc.main.webapp.pagessrc 中。 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/主/资源 <强> /.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>

...

关于java - Maven 未将 HTML 正确放入 WAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20033593/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com