简体   繁体   English

如何在Java Applet中使用带扩展名的Apache FOP(FE Barcode4j)

[英]How to use apache fop with extensions (f.e. barcode4j) in java applet

I want to have a barcode (Code128) generated during the xsl fop translation. 我想在xsl fop转换期间生成条形码(Code128)。 As it is said in the apache fop documentation (and barcode4j docs), if you want to use extension, put it on the classpath. 如apache fop文档(和条形码4j文档)中所述,如果要使用扩展名,请将其放在类路径中。 This works fine for a desktop app and an applet running from the eclipse. 这对于桌面应用程序和从Eclipse运行的applet都很好。 But how to run it from a browser? 但是如何从浏览器运行它呢?

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". 作为概念验证,我将所有内容提取到所谓的“ fat-jar”(一个胖子),将所有东西从日食中重新打包为“导出到可运行的jar”,并用“将所需的库提取到生成的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? 这是我唯一的apache fop扩展,所以我猜问题出在关于类路径的问题上,因为applet没有这样的东西?

Here is my main part of the html: 这是我的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>

and jnlp: 和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>

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. 我将在Java控制台上添加一个标准的乱码(“ 19:43:04,429 WARN FOUserAgent:97-遇到未知格式对象“ { http://barcode4j.krysalis.org/ns }高度”(代码128的子代)。 (没有可用的上下文信息)”),因为我没有包含正确的完整条形码4扩展名,但是我检查了所有内容,并将其正确打包在jar文件中,并且在eclipse中正常运行。

This is copy/paste example code from the barcode4j webpage: 这是从barcode4j网页复制/粘贴的示例代码:

<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>

I am using latest barcode4j-fop-ext-complete.jar and apache-fop 1.1. 我正在使用最新的条形码4j-fop-ext-complete.jar和apache-fop 1.1。 What am I doing wrong? 我究竟做错了什么?

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). FOP扩展是由JAR服务提供者机制 (META-INF / services方法)发现的。 That means you have to combine, rather than overwrite, the files in META-INF/services. 这意味着您必须合并而不是覆盖META-INF / services中的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM