Jasperreport + ireport 无法取得路径解决办法(unix操作系统,weblogic服务)

         Jasperreport report;         

 

         Map parameters = new HashMap();   //报表变量

         List<PaymentNoticeBean> paymentNotices =***;  //报表数据

 
         //子报表数据源
         parameters.put("datasetsub",new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(paymentNotices));
         //子报表参数
        parameters.put("paramsub",parameters);

 

         //得到class根目录
          String classes_root= this.getClass().getClassLoader().getResource("/").getPath();
          String realPath = "/";
          //class根目录向上两级,跳过/WEB-INF/class
          for(int i=1;i<classes_root.split("/").length;i++) {
           if(i == classes_root.split("/").length-2){
            break;
           }
           realPath +=classes_root.split("/")[i]+"/";
          }
          realPath = realPath + "***/***/";  //子报表所在文件夹 绝对路径
          
         parameters.put("pathSubJasper",realPath);

 

         report.setSrc("/***mainReport.jasper");

 

         report.setParameters(parameters);
         net.sf.jasperreports.engine.data.JRBeanCollectionDataSource ds = new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(
     paymentNotices);
        report.setDatasource(ds);
        report.setType("html");
        report.setVisible(true);

你可能感兴趣的:(jasperReport)