Java toRealPath() fails(Jasper)

I am currently tying to use jasper report in Java project , i was able to design report and compile jasper but getting issue when running report , i am currently facing issue with loading subreports and images. Below is the folder structure of jasper reports

  • com(package of applications)
  • net(package of jasper)
  • resources
    • jasperreport
      • main.jasper
      • subreport1.jasper

in main.jasper ( i am referring to images and subreport1.jasper) , below is the code , this throws exception as byte data not found

<subreportExpression><![CDATA["/resources/jasperreport/subreport1.jasper"]]></subreportExpression> 

I tried with below approach , this throws exception as byte data not found

<subreportExpression><![CDATA["subreport1.jasper"]]></subreportExpression> 

Below is code that works

<subreportExpression><![CDATA["resources/jasperreport/subreport1.jasper"]]></subreportExpression> 

Though above mentioned approach works but i get warning

Failed to resolve real path for file resources/jasperreport/subreport1.jasper

I did check code of Jasper it tries to load file using below code

 file.toPath().toRealPath() 

once above code fails we get warning , not sure why toRealtPath does not work Thought it is able to load using directly resources/jasperreport/subreport1.jasper without usign toRealpath option .

Any suggestion on file path to be used.

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.