如何在Java Applet中使用带有扩展名(例如条形码4j)的Apache FOP [英] How to use apache fop with extensions (f.e. barcode4j) in java applet

查看:105
本文介绍了如何在Java Applet中使用带有扩展名(例如条形码4j)的Apache FOP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在xsl fop转换期间生成条形码(Code128).如apache fop文档(和barcode4j文档)所述,如果要使用扩展名,请将其放在类路径中.这对于桌面应用程序和从Eclipse运行的applet都很好.但是如何从浏览器运行它呢?

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"和将所需的库提取到生成的JAR中".除条码生成外,其他所有操作均按预期进行(翻译和许多其他操作).这是我唯一的apache fop扩展,所以我猜问题出在关于类路径的问题上,因为applet没有这样的东西?

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 }高度"(代码为128的子代.(无可用的上下文信息)"),因为我不包括正确的完整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.

这是从条形码4j网页复制/粘贴的示例代码:

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>

我正在使用最新的条形码4j-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?

推荐答案

如果不小心,创建胖罐"可能会丢失重复文件. 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 Applet中使用带有扩展名(例如条形码4j)的Apache FOP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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