Printing from Java does not work

Bug #86970 reported by Johann Petrak
20
Affects Status Importance Assigned to Milestone
sun-java5 (Ubuntu)
Invalid
Undecided
Unassigned
sun-java6 (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

This applies to a current Feisty Fawn installation as of 2007-02-20.
I have installed Java 1.6.0 using the Sun download packages.

Printing from any java application (e.g. Netbeans, Jedit) to a CUPS printer does not work because the Java application complains about the printer not accepting jobs. However, the printer is accepting jobs and does work without problems from other applications.

There is a workaround: when changing the printer name so that it does not contain hyphens (by editing /etc/cups/printers.conf) printing from Java applications does work. Unfortunately, printer names cannot be changed through the printers dialog from the control center.

description: updated
Revision history for this message
magilus (magilus) wrote :

So, you tried the sun-java6-* package?

Does this also appear for the sun-java5-* package?

Revision history for this message
Johann Petrak (johann-petrak) wrote :

No, I installed Java by downloading the Linux package directly from java.sun.com and installing to my homedir. However I also tried this by running jedit with the jdk version 1.5.0_09 (also directly downloaded and manually installed from Sun) and there the problem exists also.

Revision history for this message
magilus (magilus) wrote :

It is not a valid bug against Ubuntu if you use a package which does not come from the Ubuntu Repositories.

That's why it would be nice to know if it also happens with the Java 5 + 6 shipped with Ubuntu.

I tried both versions but for me, both pop up an error in Jedit regardless if I have a hyphen set for my printer name.

Revision history for this message
Frank Wilson (fajwilson) wrote :

I'm using sun-java5 packages in edgy and cannot print. A simple way to test would be to run http://java.sun.com/docs/books/tutorial/2d/printing/examples/HelloWorldPrinter.java . When I run this and click "Print Hello World" I get "No Print Service Found" .

Revision history for this message
Tom G (tagra123) wrote :

The following will let the Java print dialog display but it still fails to print in Ubuntu using Java 1.6. It might work on others. I haven tried other version. This also fixes the Netbeans 5.5 printing problem in Ubuntu. I don't know if this hack will make other programs not print properly, especially those that need libcups.so

sudo mv libcups.so _libcups.so

To undo this change

sudo mv _libcups.so libcups.so

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6516881

Revision history for this message
fhucho (fhucho) wrote :

I have Feisty Fawn, java packages sun-java6-* and cups version 1.2.8. When I tried to print from my Java application a message "No print service found" appeared. I googled a solution - create a file /etc/cups/client.conf and put a single line "ServerName localhost" in it (without the quotation marks). After that, it works OK.

Revision history for this message
Adriaan Peeters (apeeters) wrote :

The fix by fhucho does the job for me. Im am running the same config.

Revision history for this message
Andreas Wenger (andi-xenoage) wrote :

I (any many others...) had the same problem: The printer did not accent jobs.

This can be fixed in this way:

* create a link from /usr/lib/libcups.so to /usr/lib/libcups.so.2
* edit /etc/cups/cupsd.conf : remove the line "Listen /var/run/cups/cups.sock"
* restart CUPS

But then an empty page is printed. This can be fixed in this way:

# cp /usr/lib/cups/filter/pstops /usr/lib/cups/filter/pstops.dist
# cat > /usr/lib/cups/filter/pstops

============= New pstops ==============
#!/bin/bash

JOBID="$1"
USER="$2"
TITLE="$3"
COPIES="$4"
SPEC="$5"
FILE="$6"

TEMP=`mktemp /tmp/pstops.XXXXXXX` || exit 1

# we're reading from STDIN, store it into the temporary file
if test -z "$FILE" -o ! -f "$FILE" ; then
  cat > "$TEMP"
else
  cp "$FILE" "$TEMP"
fi

# remove offending commands
sed -i -e 's/\/DeferredMediaSelection true //' "$TEMP"

# execute the command
/usr/lib/cups/filter/pstops.dist "$JOBID" "$USER" "$TITLE" \
                                 "$COPIES" "$SPEC" "$TEMP"

# removing temporary file
rm -f "$TEMP"
=======================================

Note that the location of your pstops may be different (this is for RHEL 5) and
the one in /usr/bin is NOT the one used by CUPS.

(Source: Adam C, http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6506286)

After doing that, printing works perfectly.

I have no idea who is responsibly for the bug. CUPS, Sun, the Ubuntu package? But I know from others that the problem exists with the Ubuntu JDK package as well as with the original Sun package.

Here is the discussion (but only in German): http://forum.ubuntuusers.de/topic/108231/

Revision history for this message
Matthias Klose (doko) wrote : Re: [Bug 86970] Re: Printing from Java does not work

Andi schrieb:
> I (any many others...) had the same problem: The printer did not accent
> jobs.
>
> This can be fixed in this way:
>
> * create a link from /usr/lib/libcups.so to /usr/lib/libcups.so.2

libmawt.so tries to dlopen libcups.so.2. could you verify this using strace?

Matthias Klose (doko)
Changed in sun-java5:
status: New → Incomplete
Changed in sun-java6:
status: New → Incomplete
Revision history for this message
MrTux (sstrickroth) wrote :

Andi's workaround (from 2007-08-29, ServerName localhsot and ln -s libcups.so.2 libcups.so) worked on feisty, but after an uprade to gutsy (even on a fresh install) it doesn't work again: I even cannot open the print-dialog from java

Revision history for this message
dmoyne (dmoyne-aliceadsl) wrote :

Very strange I experienced the same bug in some Java applications with jdk 1.5 or 1.6 where printing facilities cannot be accessed ; the way to solve the problem is to set a printer from the list of printers available in CUPS as "default locally" (translated into English from French display which might be "default under system") ; mind you it is not the option set as "default for user" that can be applied to another printer from the list of printers available in CUPS ; then after doing so it works ; now the question is why the first printer set in CUPS is not automatically set as "default locally" as my system at one point did not have any set and once you have one set you can unset this option only by moving it to another printer but not way to globally remove it ?

All other fixes propose by othet people do not work.

Regards.

Revision history for this message
hede (michael-heide) wrote :

this bug seems related to bug #156191

Revision history for this message
Jayson Rowe (jayson.rowe) wrote :

Since it's been a very long time since any additional info was added to this bug, I'm just checking to see if this is still an issue, and find out what additional work should be done on this bug.

Revision history for this message
Darius (darius-dons) wrote :

This happens when I am using Xilinx ISE - without the work around it gets a printer not ready exception.

Xilinx bundle their own JDK so I can't replace it :(

Revision history for this message
ali irawan (boylevantz) wrote :

I have some problem with my latest project.
I develop a web based application based on Java platform, using JSF. I use uBuntu 8.10 for the Operating System.

The web application would show list of available Print Service
in a DropDownList.

public SelectItem[] getPrintServiceList() {
        SelectItem[] arr = null;

        PrintService[] service = PrintServiceLookup.lookupPrintServices(null, null);
        System.out.println(service.length);
        arr = new SelectItem[service.length];
        for (int i = 0; i < service.length; i++) {
            System.out.println(service[i].getName());
            arr[i] = new SelectItem(service[i].getName(), service[i].getName());
        }
        return arr;
    }

But what happen... the list won't show. The weird things i do test deploy the same application in Windows platform and it works!

I have tried to create a simple application (Console based), to use lookupPrintService method, and it works. it shows all printer that has been set up in CUPS.

Output:
Canon
Tally

But why it won't show in Web Application (in DropDownList).
Any body can help me.

Below i attach what should shown in Windows platform. It list all available printers. but when i deply on uBuntu, it doesnt work.

Is there any issue how to get Java Print correctly (j2ee applications) in uBuntu platform.

Revision history for this message
Alex Denvir (coldfff) wrote :

We are closing this bug report because it has not been updated for some time. Please reopen it if you have more information to submit, and don't hesitate to submit bug reports in the future. To reopen the bug report you can click on the current status, under the Status column, and change the Status back to "New". Thanks again!

Changed in sun-java5 (Ubuntu):
status: Incomplete → Invalid
Changed in sun-java6 (Ubuntu):
status: Incomplete → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.