访问 Wicket 应用程序中 Maven 依赖项的资源

huangapple go评论77阅读模式
英文:

Acessing resource of a maven dependency in a wicket application

问题

我有两个Maven项目。

components: 包含Wicket组件。所有这些Wicket组件都依赖于一个名为component.css的单个样式表。该样式表由libsass-maven-plugin生成,并输出到projet.build.directory(直接放在target文件夹中)。此项目被打包为一个jar文件。

web-app: 这是(Wicket)Web应用程序的项目,打包为一个war文件。

我的问题是,我找不到一种在我的web-app项目中将component.css作为外部资源包含的方法。

我尝试过使用maven-war-plugin将其包含到webapp文件夹中,并在HTML中将其作为<link>加载,但这并不起作用,因为components不是一个war项目。

然后我尝试使用new CssResourceReference(SomeClass.class, "/component.css")来让Wicket生成<link>元素,但我得到一个错误,说访问(静态)包资源被拒绝。

我最后的可能解决方案是在components内部创建一个类,并相对于该类生成component.css。但不知何故,即使这样也不起作用。

英文:

I have two maven projects.

components: Contains wicket components. All of these wicket components rely on a single stylesheet called component.css. The stylesheet is generated by the libsass-maven-plugin and output to the projet.build.directory. (Directly into the target folder) This project is packaged as a jar.

web-app: This is the project for the (wicket) web application packaged as a war.

My problem is, that I just can't find a way to include the componet.css as a external resource in my web-app project.

I tried to include it into the webapp folder using the maven-war-plugin and loading it as a &lt;link&gt; inside the html, but that didn't work, because components isn't a war project.

Then I tried to use new CssResourceReference(SomeClass.class, &quot;/component.css&quot;) to let wicket generate the &lt;link&gt; element, but I get an error that the access to (static) package resource is denied.

My last possible solution was to create a class inside components and generate the component.css relative to that class. But somehow even this isn't working.

答案1

得分: 1

然后我尝试使用新的 CssResourceReference(SomeClass.class, "/component.css") 来让 Wicket 生成 <link> 元素,但是我得到了一个错误,说访问(静态)包资源被拒绝。

这应该是可以工作的。Wicket 的默认设置允许提供 .css 静态文件 [1]。您是否使用了自定义的 IPackageResourceGuard 来禁用了 .css 文件?

  1. https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/html/PackageResourceGuard.java
英文:

> Then I tried to use new CssResourceReference(SomeClass.class, "/component.css") to let wicket generate the <link> element, but I get an error that the access to (static) package resource is denied.

This should work. Wicket's default settings allow .css static files to be served [1]. Do you use a custom IPackageResourceGuard that disables .css ?

  1. https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/html/PackageResourceGuard.java

huangapple
  • 本文由 发表于 2020年10月6日 18:23:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/64223875.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定