用java从AS400服务器获取打印机

发布于 2024-11-30 13:57:42 字数 195 浏览 2 评论 0原文

我无法获取 AS400 上的打印机。

我尝试过:

PrintService[] services = PrinterJob.lookupPrintServices();

没有找到任何服务。

我还搜索了 JTOpen API。我什么也没找到。

有人可以帮助我吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏至、离别 2024-12-07 13:57:42

PrinterJob.lookupPrintService() 默认为 DocFlavor.SERVICE_FORMATTED.PAGEABLE 风格。可能是您没有支持该风格的打印机。

尝试运行此命令来检查是否找到任何打印机

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]);
           }
       }

并检查它们支持哪些类型。

另外,你用的是iSeries吗?操作系统400?哪个Java?

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?

等往事风中吹 2024-12-07 13:57:42

我面临同样的问题,终于找到了解决方案:根据 Java 打印服务 IBM 文档 您必须将 2 个 jar 添加到 Java 的类路径中,以检测 AS400 上的打印机(和打印)。

这些 jar 文件应位于

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

在我的例子中,AS400 上的 jt400Native.jar 对于我们的应用程序来说太旧了(Java 1.1 与 Java 1.8),导致应用程序启动时崩溃。我从 https://mvnrepository.com/artifact/net.sf 获取了最新的一份。 jt400/jt400 并且成功了。

如果您从 jar 运行应用程序,则无法使用 -cp-classpath,这些选项将被忽略,因为类路径是通过 Manifest 文件设置的。
就我而言(SpringBoot Java 8 Gradle 项目),我曾经

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

将这些 jar 添加到 Manifest 文件中的类路径中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文