net.sf.jasperreports.engine.util.JRResourcesUtil.findClassLoaderResource(Ljava /郎/字符串; Ljava /郎/类加载器;)

时间:2016-08-20 00:00:06

标签: java jasper-reports

我正在尝试将数据库中的用户列表导出为pdf。当我点击我的"打印表"按钮此异常返回。 Button正在执行generateReport()方法。

一些细节:

  • iReport 5.5.0
  • net.sf.jasperreports 5.5.0(pom.xml)
  • jasperreports 3.5.3(pom.xml)
  • Glassfish 4.0
  • JDK 1.8
  • Netbeans 8.1

Glassfish日志文件在这里:

[2016-08-20T02:31:33.161+0300] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=25 _ThreadName=Thread-3] [timeMillis: 1471649493161] [levelValue: 800] [[
  generateReport()]]
[2016-08-20T02:31:33.161+0300] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=25 _ThreadName=Thread-3] [timeMillis: 1471649493161] [levelValue: 800] [[
  TTTT -:C:\Users\Burak\Documents\NetBeansProjects\question3\target\question3-1.0-SNAPSHOT\jasper\JRUser1.jrxml]]
[2016-08-20T02:31:33.163+0300] [glassfish 4.0] [SEVERE] [] [] [tid: _ThreadID=25 _ThreadName=Thread-4] [timeMillis: 1471649493163] [levelValue: 1000] [[
  Sat Aug 20 02:31:33 EEST 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.]]
[2016-08-20T02:31:33.165+0300] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=25 _ThreadName=Thread-3] [timeMillis: 1471649493165] [levelValue: 800] [[
  Context Path is  : =C:\Users\Burak\Documents\NetBeansProjects\question3\target\question3-1.0-SNAPSHOT\jasper\JRUser1.jrxml]]
[2016-08-20T02:31:33.645+0300] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=25 _ThreadName=Thread-3] [timeMillis: 1471649493645] [levelValue: 800] [[
  Compiling Report Designs]]
[2016-08-20T02:31:34.082+0300] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=25 _ThreadName=Thread-3] [timeMillis: 1471649494082] [levelValue: 800] [[
  Creating JasperPrint Object]]
[2016-08-20T02:31:34.107+0300] [glassfish 4.0] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=25 _ThreadName=http-listener-1(1)] [timeMillis: 1471649494107] [levelValue: 900] [[
  StandardWrapperValve[users]: Servlet.service() for servlet users threw exception
java.lang.NoSuchMethodError: net.sf.jasperreports.engine.util.JRResourcesUtil.findClassLoaderResource(Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/net/URL;
    at net.sf.jasperreports.repo.DefaultRepositoryService.getInputStream(DefaultRepositoryService.java:141)
    at net.sf.jasperreports.repo.InputStreamPersistenceService.load(InputStreamPersistenceService.java:48)
    at net.sf.jasperreports.repo.DefaultRepositoryService.getResource(DefaultRepositoryService.java:187)
    at net.sf.jasperreports.repo.RepositoryUtil.findInputStream(RepositoryUtil.java:304)
    at net.sf.jasperreports.repo.RepositoryUtil.getInputStreamFromLocation(RepositoryUtil.java:275)
    at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontFamilies(SimpleFontExtensionHelper.java:183)
    at net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.getExtensions(FontExtensionsRegistry.java:56)
    at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:107)
    at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:80)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:177)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:78)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:60)
    at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:147)
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:57)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:421)
    at obss.question3.springmvc.controller.ListUserController.generatePdfReport(ListUserController.java:95)
    at obss.question3.springmvc.controller.ListUserController.generateReport(ListUserController.java:66)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
    at java.lang.Thread.run(Thread.java:745)
]]

网络浏览器出错:

HTTP Status 500 - Internal Server Error

type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoSuchMethodError: net.sf.jasperreports.engine.util.JRResourcesUtil.findClassLoaderResource(Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/net/URL;
root cause

java.lang.NoSuchMethodError: net.sf.jasperreports.engine.util.JRResourcesUtil.findClassLoaderResource(Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/net/URL;
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.0 logs.

GlassFish Server Open Source Edition 4.0

ListUserController在这里:

@Controller
public class ListUserController {

    @Autowired
    UserService userService;

    @Autowired
    ServletContext context;

    @RequestMapping(value = "/list-users", method = RequestMethod.GET)
    public ModelAndView listUsersPage() {
        ModelAndView model = new ModelAndView();
        model.addObject("title", "Web Demo with Spring Security");

        model.addObject("person", new Users());
        model.addObject("listPersons", this.userService.getAllUsers());

        System.out.println("listusers()");
        model.setViewName("/secured/list-users");
        return model;
    }

    @RequestMapping(value = "/generateReport", method = RequestMethod.POST)
    public String generateReport(HttpServletRequest request, HttpServletResponse response) throws JRException {
        System.out.println("generateReport()");
        HashMap<String, Object> hmParams = new HashMap<>();
        hmParams.put("Title", "Test");

        String contextPath = request.getServletContext().getRealPath("/jasper/JRUser1.jrxml");

        System.out.println("TTTT -:" + contextPath);

        try {
            generatePdfReport(request); //Line 66
        } catch (SQLException ex) {
            Logger.getLogger(ListUserController.class.getName()).log(Level.SEVERE, null, ex);
        }

        return "redirect:/list-users";
    }

    public void generatePdfReport(HttpServletRequest request) throws SQLException {

        String contextPath = request.getServletContext().getRealPath("/jasper/JRUser1.jrxml");

        JasperConnection jc = new JasperConnection();
        Connection conn = jc.getConn();

        try {

            InputStream input = new FileInputStream(new File(contextPath));

            System.out.println("Context Path is  : =" + contextPath);
            JasperDesign jasperDesign = JRXmlLoader.load(input);

            System.out.println("Compiling Report Designs");
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

            System.out.println("Creating JasperPrint Object");
            Map<String, Object> parameters = new HashMap<>();
            parameters.put("ReportTitle", "PDF JasperReport");

            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn); //Line 95

            File f = new File("/webapp/UserReport.pdf");
            f.createNewFile();

            // Exporting the report
            OutputStream output = new FileOutputStream(f);

            JasperExportManager.exportReportToPdfStream(jasperPrint, output);

            System.out.println("Report Generation Complete");
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

JasperConnection就在这里:

public class JasperConnection {

    public Connection getConn() {
        try {
            String url = "jdbc:mysql://localhost:3306/question3?zeroDateTimeBehavior=convertToNull";
            String user = "root";
            String password = "password";

            // Load the Connector/J driver
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            // Establish connection to MySQL
            Connection conn = DriverManager.getConnection(url, user, password);

            return conn;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

JRUser1.jrxml在这里:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" 
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
              xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports 
http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" 
              name="JRUser1" pageWidth="595" pageHeight="842" columnWidth="555" 
              leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <queryString language="SQL">
        <![CDATA[SELECT
     users.`username` AS users_username,
     users.`email` AS users_email,
     users.`birthday` AS users_birthday,
     users.`sex` AS users_sex
FROM
     `users` users]]>
    </queryString>
    <field name="users_username" class="java.lang.String"/>
    <field name="users_email" class="java.lang.String"/>
    <field name="users_birthday" class="java.sql.Date"/>
    <field name="users_sex" class="java.lang.Integer"/>
    <group name="users_username">
        <groupExpression><![CDATA[$F{users_username}]]></groupExpression>
    </group>
    <group name="users_email">
        <groupExpression><![CDATA[$F{users_email}]]></groupExpression>
    </group>
    <group name="users_birthday">
        <groupExpression><![CDATA[$F{users_birthday}]]></groupExpression>
    </group>
    <group name="users_sex">
        <groupExpression><![CDATA[$F{users_sex}]]></groupExpression>
    </group>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch">
            <staticText>
                <reportElement x="10" y="0" width="100" height="20"/>
                <text><![CDATA[User Report]]></text>
            </staticText>
        </band>
    </pageHeader>
    <columnHeader>
        <band height="20" splitType="Stretch">
            <staticText>
                <reportElement x="10" y="0" width="100" height="20"/>
                <text><![CDATA[Username]]></text>
            </staticText>
            <staticText>
                <reportElement x="110" y="0" width="170" height="20"/>
                <text><![CDATA[Email]]></text>
            </staticText>
            <staticText>
                <reportElement x="280" y="0" width="100" height="20"/>
                <text><![CDATA[Birthday]]></text>
            </staticText>
            <staticText>
                <reportElement x="380" y="0" width="100" height="20"/>
                <text><![CDATA[Sex]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement x="10" y="4" width="100" height="15"/>
                <textElement textAlignment="Left"/>
                <textFieldExpression><![CDATA[$F{users_username}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement positionType="Float" x="120" y="4" width="170" height="15"/>
                <textFieldExpression><![CDATA[$F{users_email}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement positionType="Float" x="280" y="4" width="100" height="15"/>
                <textFieldExpression><![CDATA[DateFormat.getDateInstance(DateFormat.MEDIUM, $P{REPORT_LOCALE}).format( $F{users_birthday} )]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement positionType="Float" x="380" y="4" width="100" height="15"/>
                <textFieldExpression><![CDATA[$F{users_sex}.equals( new Integer(0) ) ? "Male" : "Female"]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

我删除了.jrxml中的uuid部分。 uuid属性导致另一个例外。

users_sex字段类型是smallint mysql。 iReport自动创建类型为java.lang.Integer的.jrxml文件。

JRUser1.jrxml预览:

enter image description here

我搜索了但我无法找到任何解决方案。

1 个答案:

答案 0 :(得分:1)

当您拥有相同的 lib 2版本

时,会发生此问题

不要关闭流生成器文件.pdf

此调查解决方案

  • run maven
  • 依赖:树
  • 分析您的依赖项duplicante
  • 删除更多旧的依赖
  • 看你的方法generatePdfReport很多流未关闭,你需要关闭所有打开的流