Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

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

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?

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>

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

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>

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...