0

I am writing a program in java with netbeans IDE which receives a jasper report *.jrxml and then displays the report for the user. I wrote the following line of code for the file path

String reportSource = "src\\jasper-reports\\report.jrxml";  

but when I move the dist folder in some other place and try to run the jar file inside it, my program can not find the report.

my problem is that were should I put the *.jrxml file and how to define it's path in my program so that when I want to give my software to someone else it runs without any errors (e.g. the program can find the file)

3
  • 1
    You need to include it in your final jar as a resource Commented Oct 20, 2015 at 19:41
  • thanx, but how should I wrote its path in reportSource field? Commented Oct 20, 2015 at 19:42
  • Google how to use jar resources. You can read it as a stream from your jar Commented Oct 20, 2015 at 19:42

2 Answers 2

1

avoid using absolute paths. try to include the file as a resource in your netbeans project. then in your code you can search for and load the file as

new InputStreamReader((Main.class.getResourceAsStream("/report.jrxml")))

something like that depending on where the file resides in your project

Sign up to request clarification or add additional context in comments.

Comments

0

it's more recommended using one of the two approaches:

  1. pass the locations/paths as a -Dproperty=value in the Java application launcher command line http://www.tutorialspoint.com/unix_commands/java.htm

  2. store it the locations/paths in a configurations file with a unique key and edit the file accordingly for different environments, e.g.this files always stored in ${HOME}/config_files/ directory

absolute paths considered a bad practice

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.