Rebuilding the JAR file "qz-print.jar" with the reduced/modified source code.

125 views
Skip to first unread message

Shivam Saxena

unread,
Jun 4, 2015, 7:36:42 AM6/4/15
to jzebra...@googlegroups.com
Hi everyone,

I am trying to trim down the source code of this application as I just need to use two features of this applet-
1. printToHost()
2. print() using default printer

I have successfully integrated this applet in my project with the full JAR file- qz-print.jar and it is working fine.

What I plan to do now is to reduce the source code to increase the efficiency as i do not need so much functionality and then build the JAR file qz-print.jar once again & replace the old jar file with the new one.

I noticed that the original jar file had two extra folders JNLP-INF and META-INF along with the source folder 'qz'.

First I tried to build the JAR file with the full source code without any modifications. To do this, I made a new JAVA Project in my Eclipse workspace & copied the source code folder 'qz', META-INF and JNLP-INF in my src folder. I also included the necessary extra JAR files in the Build Path. Then I exported the project as a JAR file & selected "META-INF/MANIFEST.MS" as the manifest file.

But when I replace the old JAR file with this new JAR file, the plugin does not load properly. The background does not change & when i click on any button, I get the message- "Plugin not loaded properly."

It would be a great help if you could walk me through the steps of creating this JAR file.

Thanks.

Tres Finocchiaro

unread,
Jun 4, 2015, 9:02:31 AM6/4/15
to jZebra users
@Shivam,

The JNLP-INF directory is not mandatory unless you plan to use JNLP to launch the applet.  If you don't use JNLP and would rather use classic <applet> tags, you can remove this folder.

The MANIFEST-MF directory is usually created by the build process.  The 1.8 branch and older was built using NetBeans, so the build and packaging process was very specific.

We've just released the source code for the 1.9 branch here, which will make the build process much easier.

On a side-note, you're not going to get much benefit from removing components from the source code.  Even with all of the improvements in the 1.9 branch, the JAR is about 220KB, about 50KB of which is QZ Tray artwork.

-Tres


--
--
To unsubscribe from this group, send email to jzebra-users...@googlegroups.com
 
http://code.google.com/p/jzebra

---
You received this message because you are subscribed to the Google Groups "jZebra users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jzebra-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shivam Saxena

unread,
Jun 4, 2015, 10:06:02 AM6/4/15
to jzebra...@googlegroups.com
Hey Tres,

Thanks for such a fast reply. Actually, I found what I was looking for on this old thread-
https://groups.google.com/forum/#!topic/jzebra-users/r14QK0sZpH0

which lead me to this tutorial-
https://code.google.com/p/jzebra/wiki/TutorialSignatureChange

I managed to generate the JAR file & after all the trimming it is now 21KB.

There is one thing though I would like to point out and this is the case with the original applet as well.

When I use the "Print To Host" function and then try to select the default printer using "Use Default Printer", I get a popup saying that the default local printer is selected which is fine. But now when I print anything using any button ex- "Print ZPL", all the commands go to the "host" and "port" set while using the "Print To Host" function instead of the default local printer. I made some changes to the code to make this work but I cannot seem to make work. Are you aware of this and is there any way to overcome this?

Tres Finocchiaro

unread,
Jun 4, 2015, 10:14:41 AM6/4/15
to jZebra users

Glad you got it working.

No, I'm not aware of such a bug.  Are you sure you aren't calling the wrong function?

Shivam Saxena

unread,
Jun 4, 2015, 11:10:00 AM6/4/15
to jzebra...@googlegroups.com
No, I am pretty sure I am not doing anything wrong. I am using QZ Print Plugin 1.8.7. Just try doing this yourself once-

1. "Print To Host"
2. Try to print something on the default local printer

I checked the Java console logs, every print command is sent to the host once you click "Print To Host". To print on the local printer again, I have to reload the page.
Thanks for your help once again. :)

Tres Finocchiaro

unread,
Jun 4, 2015, 11:38:08 AM6/4/15
to jZebra users
@Shivam,

Confirmed.  This is a bug.  I had tested this very same logic yesterday, but the second printer wasn't a raw printer.

The issue starts here:


We set the output socket, but never reset it back to null.

A temporary patch would be to set it back to null here using socketHost.set(null);


But that can potentially still get stuck when it throws an exception up the stack, so a permanent solution will be to use try/catch/finally to null that variable out properly every time, or expose the variable to PrintApplet and control it there.

-Tres

--

Shivam Saxena

unread,
Jun 5, 2015, 2:45:12 AM6/5/15
to jzebra...@googlegroups.com
Yes you are right. I have submitted my changes on GitHub after which the issue was solved. I have tested it & it seems to work fine. Thanks for all the help. :)

Tres Finocchiaro

unread,
Jun 5, 2015, 8:19:24 AM6/5/15
to jZebra users
I have submitted my changes on GitHub 

Can you provide a link? Do you want these changes synced back into upstream?

-Tres


Shivam Saxena

unread,
Jun 5, 2015, 8:51:34 AM6/5/15
to jzebra...@googlegroups.com

Tres Finocchiaro

unread,
Jun 5, 2015, 9:47:37 AM6/5/15
to jZebra users
Thanks.  Here's the upstream change:


We won't be porting this to the 1.8 branch unless we hit a major bug with the 1.9 codebase.  Thanks for the contribution!

Shivam Saxena

unread,
Jun 8, 2015, 11:17:53 AM6/8/15
to jzebra...@googlegroups.com
Happy to help.
Reply all
Reply to author
Forward
0 new messages