小程序内的 JAXB - 未找到 package-info.class

发布于 2024-09-15 00:07:51 字数 2466 浏览 4 评论 0原文

我们有一个从小程序内部使用 JAXB 的 Web 应用程序。一切工作正常,除了首次创建 JAXBContext 时,我们在小程序控制台中看到以下记录:

Creating JAXBContext...
network: Connecting https://myserver.com/MyApp/CC.ccc with proxy=DIRECT
network: Connecting https://myserver.com/MyApp/CC.ccc with cookie "__utma=69126149.1559268128.1262793475.1265211768.1271711769.3; JSESSIONID=723072c1c4bbc2598e402b3f24a5d12f3324"
network: Cache entry not found [url: https://myserver.com/MyApp/com/comm/servlet/generated/package-info.class, version: null]
network: Connecting https://myserver.com/MyApp/com/comm/servlet/generated/package-info.class with proxy=DIRECT
network: Connecting http://myserver.com:443/ with proxy=DIRECT
network: Connecting https://myserver.com/MyApp/com/comm/servlet/generated/package-info.class with cookie "__utma=69126149.1559268128.1262793475.1265211768.1271711769.3; JSESSIONID=723072c1c4bbc2598e402b3f24a5d12f3324"

这种情况总共发生了 20 次,并且大大减慢了我们的应用程序的速度。

我正在使用“xjc”ant 任务 (com.sun.tools.xjc.XJCTask) 将我们的模式编译为 com/comm/servlet/ generated/ 包中的 Java。代码生成得很好,但没有 package-info.java。如果我手动创建此文件并编译和打包代码,则 JAR 文件中会缺少 package-info.class。

这是我的 XJC 任务:

<target name="generateJAXBSource">
 <taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
   <classpath>
     <fileset dir="lib/jaxb" includes="*.jar" />
   </classpath>
 </taskdef>

 <xjc schema="resources/requests/111.xsd" 
  destdir="src" 
  package="com.comm.servlet.generated"/>  
</target>

我的 XSD 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:xml="http://www.w3.org/XML/1998/namespace">
 <xs:import namespace="http://www.w3.org/XML/1998/namespace" />

 <xs:element name="InfoResponse">
  <xs:complexType>
   <xs:sequence>
    <xs:element ref="WorkQueueItem" maxOccurs="unbounded" />
   </xs:sequence>
  </xs:complexType>
 </xs:element>

我一整天都在谷歌上搜索,但似乎不知道如何解决这个问题。

我尝试了此处提出的解决方法确保 package-info.java 被编译:

...但没有运气。

我可以指示 JAXB 不要查找 package-info.class 吗?

如何确保手动创建的 package-info.java 最终出现在 JAR 文件中?

谢谢。

We have a web application that uses JAXB from inside an applet. Everything works fine, except when the JAXBContext is first created, we see the following logged in the applet console:

Creating JAXBContext...
network: Connecting https://myserver.com/MyApp/CC.ccc with proxy=DIRECT
network: Connecting https://myserver.com/MyApp/CC.ccc with cookie "__utma=69126149.1559268128.1262793475.1265211768.1271711769.3; JSESSIONID=723072c1c4bbc2598e402b3f24a5d12f3324"
network: Cache entry not found [url: https://myserver.com/MyApp/com/comm/servlet/generated/package-info.class, version: null]
network: Connecting https://myserver.com/MyApp/com/comm/servlet/generated/package-info.class with proxy=DIRECT
network: Connecting http://myserver.com:443/ with proxy=DIRECT
network: Connecting https://myserver.com/MyApp/com/comm/servlet/generated/package-info.class with cookie "__utma=69126149.1559268128.1262793475.1265211768.1271711769.3; JSESSIONID=723072c1c4bbc2598e402b3f24a5d12f3324"

This happens a total of 20 times, and slows down our application considerably.

I'm using the "xjc" ant task (com.sun.tools.xjc.XJCTask) to compile our schema into Java in the com/comm/servlet/generated/ package. The code gets generated fine, but there is no package-info.java. If I manually create this file and compile and package the code, the package-info.class is missing from the JAR file.

This is my XJC task:

<target name="generateJAXBSource">
 <taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
   <classpath>
     <fileset dir="lib/jaxb" includes="*.jar" />
   </classpath>
 </taskdef>

 <xjc schema="resources/requests/111.xsd" 
  destdir="src" 
  package="com.comm.servlet.generated"/>  
</target>

My XSD looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:xml="http://www.w3.org/XML/1998/namespace">
 <xs:import namespace="http://www.w3.org/XML/1998/namespace" />

 <xs:element name="InfoResponse">
  <xs:complexType>
   <xs:sequence>
    <xs:element ref="WorkQueueItem" maxOccurs="unbounded" />
   </xs:sequence>
  </xs:complexType>
 </xs:element>

I've been googling all day but can't seem to figure out how to get around this.

I tried the workaround proposed here to make sure package-info.java gets compiled:

... but no luck.

Can I instruct JAXB not to look for package-info.class?

How can I make sure that my manually created package-info.java ends up in the JAR file?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心头的小情儿 2024-09-22 00:07:51

您的 JAXB 实现正在寻找 package-info.class 来处理模型中可能存在的任何包级别注释。没有标准方法可以阻止 JAXB 实现查找包级别注释。

添加 package-info 类(与模型类在同一包中)似乎是一个合理的解决方法。

package-info 是否无法为您编译(如果是,您会收到什么错误)?或者它只是没有出现在您的 JAR 中(如果是的话,您如何构建您的 JAR)?

Your JAXB implementation is looking for package-info.class to process any package level annotations that might be present in your model. There is no standard way to prevent a JAXB implementation from looking for package level annotations.

Adding a package-info class (in the same package as your model classes) seems like a reasonable work around.

Is package-info failing to compile for you (if so what error are you getting)? Or is it just not appearing in your JAR (if so how are you building your JAR)?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文