François
François

Reputation: 11

get the printers in java from the AS400 server

I can't get the printers on the AS400.

I tried :

PrintService[] services = PrinterJob.lookupPrintServices();

No services has been found.

I also searched on JTOpen API. I didn't find anything.

Somebody can help me ?

Upvotes: 0

Views: 804

Answers (2)

tinysquare
tinysquare

Reputation: 1

I was facing the same issue and finally found a solution : according to Java Print Service IBM Documentation you have to add 2 jars to the classpath for Java to detect printers (and print) on AS400.

These jar files should be located at

/QIBM/ProdData/OS400/jt400/lib/jt400Native.jar
/QIBM/ProdData/OS400/Java400/ext/ibmjps.jar

In my case the jt400Native.jar on the AS400 was way too old for our application (Java 1.1 vs Java 1.8) and caused crash on app startup. I took the latest one from https://mvnrepository.com/artifact/net.sf.jt400/jt400 and it worked.

If you run your app from a jar you cannot use -cp and -classpath, these options are ignored because classpath is set via Manifest file. In my case (SpringBoot Java 8 Gradle project), I used

bootJar {
    manifest {
        attributes(
                'Class-Path': './ibmjps.jar ./jt400.jar'
        )
    }
}

to add theses jar to the classpath in Manifest file.

Upvotes: 0

pap
pap

Reputation: 27604

PrinterJob.lookupPrintService() defaults to DocFlavor.SERVICE_FORMATTED.PAGEABLE flavor. Could be you have no printers supporting that flavor.

Try running this to check if there are ANY printers found

PrintService[] allServices =
           PrintServiceLookup.lookupPrintServices(null, null);
       for (PrintService ps : allServices)
       {
           System.out.println(ps  " supports :");
           DocFlavor[] flavors = ps.getSupportedDocFlavors();
           for (int i = 0; i < flavors.length; i+</i>)
           {
               System.out.println("\t" + flavors[i]);
           }
       }

And check what kinds of flavors they support.

Also, are you on iSeries? OS 400? And which Java?

Upvotes: 1

Related Questions