gpt4 book ai didi

java - Netbeans 无法识别外部 JAR 中的复合组件

转载 作者:搜寻专家 更新时间:2023-11-01 03:53:26 24 4
gpt4 key购买 nike

我已经将一些复合组件打包到一个 JAR 中。但是,当在另一个项目(使用 Maven)中使用它们时,Netbeans 编辑器会在使用复合组件的行下方放置红色错误行,即使项目按预期编译和运行也是如此。

复合组件 JAR 的文件夹结构如下所示:

compositeComponent.jar
META-INF
faces-config.xml
highcharts-taglib.xml
MANIFEST.MF
web.xml
maven
// maven stuff.
resources
highcharts
Chart.xhtml
Series.xhtml
Tooltip.xml
nz
co
kevindoran
highcharts
example
NZPopulationTrend.class


highcharts.taglib.xml 看起来像:

<facelet-taglib version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd">

<namespace>http://nz.co.kevindoran/highcharts-jsf</namespace>
<composite-library-name>highcharts</composite-library-name>

</facelet-taglib>


[旁注:存在 faces-config.xmlweb.xml 以允许通过将文件扩展名更改为 WAR 将“JAR”部署为 WAR(这样做是为了运行示例。]


在我当前的项目中,我已经指定了对上述项目的 Maven 依赖项,如下所示:

<dependency>
<groupId>nz.co.kevindoran</groupId>
<artifactId>jsf-menu</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

在 JSF 页面中,我使用这样的复合组件:

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:hc="http://nz.co.kevindoran/highcharts-jsf">

....

<hc:TimeChart title="Price Over Time" xLabel="Date" yLabel="Sold Price (NZD)">
<hc:TimeSeries name="Sold" series="#{cc.attrs.model.priceVsTimeChart.soldSeries}"/>
</hc:TimeChart>

....
</html>

红色错误行出现在上面的所有行下,消息:“找不到命名空间 http://nz.co.kevindoran/highcharts-jsf 的库”

如何删除这些错误行?我已经看到许多类似问题的 Netbeans 错误报告,但似乎都已解决。

此错误发生在 Netbeans 7.1、7.2 和 7.3(包括 7.3.1)上。

最佳答案

我也有同样的问题。在我的例子中,它取决于/src/main/java 文件夹。如果它存在(只存在于项目中,甚至不存在于 jar 中),则包含该库的项目会显示“找不到 namespace 的库...”当我删除它的“java”文件夹时。但是我的支持 bean 类在 jar 里不见了......

尝试使用 Netbeans 7.2 和 7.3,maven 2

解决方法:

  1. 生成第二个包含 Java 源文件的项目。 (称为:jsf-lib-java)
  2. 在 jsf-lib 项目(带有 xhtml 的复合组件项目)中删除“java”文件夹和所有 *.java 源。
  3. 在jsf-lib pom.xml中添加如下配置:


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.mycompany.project</groupId>
<artifactId>jsf-lib-java</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>src/main/</outputDirectory>
<includes>**/*.class</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

就是这样。这将生成一个包含所需 *.class 文件的“好”jar 文件。因此可以“欺骗”Netbeans。

现在我使用这个解决方案。这是一个 hack,但没有找到更好的解决方案。

关于java - Netbeans 无法识别外部 JAR 中的复合组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17130745/

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