JBoss AS 7中的PrintServiceLookup.lookupPrintService解决方案

San*_*oud 3 java printing jsf-2

我正在尝试从我的JSF Web应用程序中打印pdf文档.

当我findPrinter()从main方法调用方法时,PrintServices找到了,但是当我从网页调用此方法时PrintService找不到.下面提到的代码..

 public static void main(final String[] args) throws Exception {
    PrintTest printTest = new PrintTest();
    printTest.findPrinter();
 }

 public void findPrinter() {

    PrintService[] printServices = PrinterJob.lookupPrintServices();
    System.out.println("Print Services Length :: " + printServices.length);
    for (PrintService printService : printServices) {
        System.out.println("PrintService :: " + printService);
}

   <h:form>
    <p:commandButton value="Print" action="#{printTest.findPrinter()}"/> 
   </h:form>
Run Code Online (Sandbox Code Playgroud)

有什么建议...

San*_*oud 6

  1. 在jbossAs的modules/sun/jdk/main/module.xml中添加额外的标签,如上所述: path name ="sun/print"

  2. 从您的JRE打开resources.jar,并提取
    META-INF/services/javax.print.PrintServiceLookup并复制到JbossAS的位置模块/ sun/jdk/main/service-loader-resources/META-INF/services.

  3. 重新启动JBoss并运行该应用程序.