Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
652 views
in Technique[技术] by (71.8m points)

jasper reports - How to use csv as datasource in Jaspersoft Server?

I've been asked to develop a report using Jaspersoft studio to generate the report template and then use jaspersoft server to have users that generate the report on demand, using data from a CSV file, instead of a DB.

I've been able to generate a report locally using studio, upload the report to the server, but I'm not able to generate the report from there.

I've been looking around and every solution that is proposed is to inject the data into a DB and then generate the report using that. But in other post in the jaspersoft community, it's said that CSV support is going to be added by early 2014, so I guess it's already there.

So, What I think that might fix it is:

1) Add the CSV file to the server, but how to link the report (.jrxml) and the dataAdapter (.xml)?

Right now, I've uploaded it to /contentFiles/xls/energy.csv, but if I put that on the data adaptor, jaspersoft can't find it:

enter image description here

I assume because there is no ip to the server, so it might think it's a local file. If I use the ip to the server, in my case, http://...***:8080/jasperserver/ (* for security reasons) and add after that /contentfiles/xls/energy.csv it still can find it. So, how to link the adaptor to the csv file on the server?

Also, since this csv file will be generated from time to time:

2) There is a folder where I can place or generate the csv file to be updated on the jaspersoft server?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are a couple of steps to follow in order to have a file-based dataAdapter correctly deployed in JasperReports Server. The following steps were performed with Jaspersoft Studio 6.4.0 and JasperReports Server Pro 6.4.0.

  1. Assuming you have your CSV file in your workspace

enter image description here (I'm using the CsvDataSouce.txt from the csvdatasource sample)

you begin by creating the data adapter from the Repository Explorer view by pointing to your file and setting up the column names.

enter image description here

  1. You then export your newly created adapter to file by right-clicking it and choosing the Export To File option enter image description here (I'm saving it along the CSV file)

  2. At this point you could even delete the adapter from the Repository Explorer view and keep only the saved file to avoid any mistakes. You then create your report by picking the workspace dataAdapter and continue with your report design. enter image description here

  3. Publishing the report to the server at this stage would not push the dataAdapter files. You need to specify the report's Default Data Adapter property from the properties panel enter image description here

by picking your workspace adapter enter image description here

  1. You can now publish the report to your server and the wizard will automatically discover the additional resources to be published enter image description here

Make sure you pick the Don't use any Data Source option in the last dialog

enter image description here

  1. Your report is now linked to the one from the server with this set of properties:

    <property name="ireport.jasperserver.url" value="http://localhost:8080/jasperserver/"/>
    <property name="ireport.jasperserver.user" value="jasperadmin"/>
    <property name="ireport.jasperserver.report.resource" value="/public/CsvReport_files/main_jrxml"/>
    <property name="ireport.jasperserver.reportUnit" value="/public/CsvReport"/>
    

You can continue to work on it and Jaspersoft Studio will prompt you to republish on each save.

  1. Your CSV file is now a JasperReports Server repository resource that you can update whenever you want, either through Studio or Server's UI. If you don't want it to reside on the JasperReports Server side you could simply use an external URL pointing to your file when creating/editing the dataAdapter file.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...