如何在java小程序中使用带有扩展名(例如barcode4j)的apache fop [英] How to use apache fop with extensions (f.e. barcode4j) in java applet

查看:16
本文介绍了如何在java小程序中使用带有扩展名(例如barcode4j)的apache fop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 xsl fop 转换过程中生成一个条形码 (Code128).正如 apache fop 文档(和barcode4j 文档)中所说,如果你想使用扩展,把它放在类路径上.这适用于桌面应用程序和从 Eclipse 运行的小程序.但是如何从浏览器运行它呢?

I want to have a barcode (Code128) generated during the xsl fop translation. As it is said in the apache fop documentation (and barcode4j docs), if you want to use extension, put it on the classpath. This works fine for a desktop app and an applet running from the eclipse. But how to run it from a browser?

作为概念证明,我将所有内容提取到所谓的fat-jar"中——一个 jar,所有内容从 Eclipse 重新打包为导出到可运行的 jar",并带有将所需的库提取到生成的 JAR 中".除了条形码生成之外,一切都按预期工作(翻译和许多其他事情).这是我唯一的 apache fop 扩展,所以我猜问题出在提到的类路径上,因为小程序没有这样的东西?

As a proof of concept, I extracted everything to so called 'fat-jar' - one jar, everything repacked from the eclipse as "Export to runnable jar" with "Extract required libs into generated JAR". Everything works as expected (translation and many other things) except the barcode generation. This is my only apache fop extension so I guess the problem is about the classpath mentioned as there is no such thing for an applet?

这是我的 html 主要部分:

Here is my main part of the html:

<html lang="en-US">
  <body>
    <script src="http://www.java.com/js/deployJava.js"></script>
    <script> var attributes = { codebase:'.', code:'com.signapplet.SignApplet.class', archive:'SignApplet.jar',  width:1024, height:968};
             var parameters = {jnlp_href: 'SignApplet.jnlp'} ; 
             deployJava.runApplet(attributes, parameters, '1.6'); 
    </script>  
  </body>
</html>

和jnlp:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">
<information>
    <title>Sign Applet</title>
    <vendor>me</vendor>
</information>
<security><all-permissions/></security>
<resources>
    <j2se version="1.6+"
          href="http://java.sun.com/products/autodl/j2se"/>
    <jar href="SignApplet.jar" main="true" />
</resources>
<applet-desc 
     name="Sign Applet"
     main-class="com.signapplet.SignApplet" 
     width="300" 
     height="300" >
 </applet-desc>
 <update check="background"/>
</jnlp>

我将在 Java 控制台上添加我有标准的乱码 ("19:43:04,429 WARN FOUserAgent:97 - 未知格式对象"{http://barcode4j.krysalis.org/ns}height"遇到(code128} 的孩子.(没有可用的上下文信息)) 因为我受伤了不包括正确的完整的barcode4j 扩展名,但我检查了所有内容都正确打包在我的 jar 文件中,并且在 eclipse 中一切正常.

I will add that on java console I have standard gibberish ("19:43:04,429 WARN FOUserAgent:97 - Unknown formatting object "{http://barcode4j.krysalis.org/ns}height" encountered (a child of code128}. (No context info available)") as I wound not include the proper complete barcode4j extension but I checked and everything is packed correctly in my jar file plus everything works correctly in the eclipse.

这是来自barcode4j网页的复制/粘贴示例代码:

This is copy/paste example code from the barcode4j webpage:

<fo:block>
  <fo:instream-foreign-object>
    <barcode:barcode
          xmlns:barcode="http://barcode4j.krysalis.org/ns"
          message="my message" orientation="90">
      <barcode:code128>
        <barcode:height>8mm</barcode:height>
      </barcode:code128>
    </barcode:barcode>
  </fo:instream-foreign-object>
</fo:block>

我使用的是最新的barcode4j-fop-ext-complete.jar 和apache-fop 1.1.我做错了什么?

I am using latest barcode4j-fop-ext-complete.jar and apache-fop 1.1. What am I doing wrong?

推荐答案

如果您不小心,创建fat-jar"会带来丢失重复文件的风险.FOP 扩展由 JAR 服务提供者发现机制(META-INF/服务方法).这意味着您必须合并而不是覆盖 META-INF/services 中的文件.

Creating a "fat-jar" holds the risk of losing duplicate files if you're not careful. FOP extensions are discovered by the JAR Service Provider Mechanism (META-INF/services approach). That means you have to combine, rather than overwrite, the files in META-INF/services.

这篇关于如何在java小程序中使用带有扩展名(例如barcode4j)的apache fop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆