Java Printing Fix for Linux with CUPS
Apparently, there’s a bug in Java where people using newer version of CUPS cannot print (can’t even display the print dialog) due to a null pointer exception and this is actually a known bug. So, how do we fix this? For people who use Gnome, you can refer to this page.
However, for people who uses non gui environment such as Fluxbox, Openbox and etc (Gnome and KDE user can use these steps too), you can fix it by editing your CUPS printers configuration file. You can get edit the file at /etc/cups/printers.conf
<DefaultPrinter Printer> # Printer configuration file for CUPS v1.3.7 # Written by cupsd on 2008-09-08 11:24 . . . Option orientation-requested 3 </Printer>
Make sure you add line 7 to every configuration for every printer you’ve installed. If you cannot find the file, you probably haven’t configured any printer yet.
This fix is simply to make sure CUPS will provide a page orientation setting to Java.
The exception:
Caused by: java.lang.NullPointerException: null attribute at sun.print.IPPPrintService.isAttributeValueSupported(IPPPrintService.java:1147) at sun.print.ServiceDialog$OrientationPanel.updateInfo(ServiceDialog.java:2121) at sun.print.ServiceDialog$PageSetupPanel.updateInfo(ServiceDialog.java:1263) at sun.print.ServiceDialog.updatePanels(ServiceDialog.java:437) at sun.print.ServiceDialog.initPrintDialog(ServiceDialog.java:195) at sun.print.ServiceDialog.(ServiceDialog.java:124) at javax.print.ServiceUI.printDialog(ServiceUI.java:188) at sun.print.RasterPrinterJob.printDialog(RasterPrinterJob.java:855) at sun.print.PSPrinterJob.printDialog(PSPrinterJob.java:421)
Refer to some of the discussions here:
UPDATE: I forgot to add, you need to restart your CUPS after editing the configuration (Thanks to Brandon Bell)
Tested on Slackware 12.1, JDK 1.6 Update 7, CUPS 1.3.7











Confirmed to work under Gentoo 2007.1
Thanks, been killing me since I have to use Matlab for one of my Math classes.
Also, I had to restart cups via
/etc/init.d/cupsd restart
to get this to work for me.
Brandon Bell
11 Sep 08 at 07:00 AM
Confirmed to work on Arch. Thanks for this fix!
Carl
5 Oct 08 at 06:00 PM
This does not fix the problem on Kubuntu 8.04 amd64. Help?
Philip Schlesinger
16 Oct 08 at 03:55 AM
PS I am running sun-java5-jdk 1.5.0_15-b04
Philip Schlesinger
16 Oct 08 at 03:55 AM
Confirmed to work on Fedora 9 with jdk 1.6.
Thanks :)
Andriy
18 Oct 08 at 12:00 AM
@Philip Schlesinger
I’m not sure what’s wrong, but it looks like as if you’re still stuck with the same problem, so, maybe you should try the tutorial from the scratch again and make sure this time you follow it correctly.
By the way, I haven’t test this solution with JDK 5 (the one that you’re using), maybe that’s the problem, try install ng JDK 6 and see if the problem still persists. If it’s not, then, this tutorial is not suitable for JDK 5.
Good luck trying :)
amree
18 Oct 08 at 12:10 PM
[...] jsme také na problém s tiskem z Javy pod Linuxem. Museli jsme přidat hack, abychom byli schopni v Linuxu [...]
SoftEU s.r.o. » Archív » WinStrom 10: pod pokličkou
23 Oct 08 at 02:06 PM
Doesn’t work for me either (Kubuntu 8.04, CUPS 1.3.7).
I’ve added the orientation-requested line in my local printers.conf and in printers.conf of my cups server and still get the same java exception.
Toni
24 Oct 08 at 06:54 PM
Confirmed to work on Ubuntu 8.10 – using Buzan’s iMindMap software
Paul
5 Nov 08 at 03:08 AM
[...] girovagato per i meandri della rete per una buona mezz’ora mi sono finalmente imbattuto in questo post (tra l’altro abbastanza recente), che contiene una soluzione molto semplice e rapida al [...]
Java printing & CUPS « DoppiaVu’s Blog
11 Nov 08 at 02:17 AM
Works like a charm! Thanks for the easy fix!
Bart
14 Nov 08 at 10:45 PM
thx for that workaround.
ulli
8 Jan 09 at 08:27 PM
Confirmed to work for Mandriva Powerpack 2009.0 printing from IntelliJ/Jedit
Darren
9 Feb 09 at 03:45 PM
Confirmed to work on Suse 11.1 64-bit with java version “1.5.0_16″
John Zoetebier
25 Mar 09 at 06:59 AM
Hi, it works on Debian Squeeze amd64 (jdk 1.6) with JEdit, but not with Eclipse … Any Idea?
Kawanokami
15 Apr 09 at 09:29 PM
It Worrrrrrrrrrrrks! Awesome! Thank you…
OS: Suse 11.1 x64
JAVA: Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_18-b02, mixed mode)
There are 10 types of people, those who understands binary, and those who doesn’t…
il Santi
29 May 09 at 08:57 PM
I spent my day investigating this issue on fedora 8.
I use a mix of printers for text printing with console text applications, for which I don’t need ppd files, and some on graphical environment, one using java.
I have printer classes declared to group the printers by function type into the console text applications.
The java test application (Print2DPrinterJob) from Sun didn’t want to work until I declared a ppd file for each printer and also inserted the “Option orientation-requested 3″ for each printer class. The classes file is named “/etc/cups/classes.conf”.
Osvaldo Marques Junior
8 Sep 09 at 12:27 PM
OS: SUSE 11.2 x32
JAVA: Java 1.6.0_04-b12 with Sun Microsystems Inc. (MATLAB)
Thanks for your help, this fixed the problems nicely.
Chistian Stoeckl
14 Apr 10 at 09:46 PM