Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6960677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:25:57+00:00 2026-05-27T15:25:57+00:00

I have a pretty simple directory layout for my Maven/Eclipse project: . ├── pom.xml

  • 0

I have a pretty simple directory layout for my Maven/Eclipse project:

.
├── pom.xml
└── src
    ├── main
    │   ├── java
    │   │   ├── org
    │   │   │   └── tkassembled
    │   │   │       └── maven
    │   │   │           └── jasperreports
    │   │   │               └── JasperReportsApplication.java
    │   │   └── sampleReport.xml
    │   └── resources
    └── test
        ├── java
        └── resources

11 directories, 3 files

As you can see, I’ve got the sampleReport.xml file in the base of the Java source dir, but when I try to open it, I get a FileNotFoundException:

Exception in thread "main" java.io.FileNotFoundException: sampleReport.xml (No such file or directory)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:137)
    at org.tkassembled.maven.jasperreports.JasperReportsApplication.main(JasperReportsApplication.java:34)

Here’s my pom.xml:

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>org.tkassembled.maven</groupId>
    <artifactId>jasperreports-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>JasperReports Testing</name>

    <dependencies>
        <!-- SLF4J -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.4</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>log4j-over-slf4j</artifactId>
            <version>1.6.4</version>
        </dependency>
        <!-- Logback -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.0.0</version>
        </dependency>
        <!-- JasperReports -->
        <dependency>
            <groupId>jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>3.5.3</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

And here’s my Java application:

package org.tkassembled.maven.jasperreports;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.net.URI;
import java.net.URL;

import net.sf.jasperreports.engine.JasperCompileManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JasperReportsApplication {

    private static final Logger logger = LoggerFactory.getLogger(JasperReportsApplication.class);

    /*
     * There are basically four steps to a finished product:
     *      <X> Design a report with a JRXML file.
     *      <X> Compile the report to a binary, serialized JasperReport and save to disk.
     *      <X> Fill the compiled report with data.
     *      <X> Export it.
     */
    public static void main(String[] args) throws Exception {
        File jrxml = new File("sampleReport.xml");
//      URL url = JasperReportsApplication.class.getResource("sampleReport.xml");
//      File jrxml = new File(url.getFile());
        assert jrxml.exists();
        assert jrxml.isFile();

        File compileTarget = File.createTempFile("output", "jasper");

        FileInputStream jrxmlInput = new FileInputStream(jrxml);
        FileInputStream jasperInput = new FileInputStream(compileTarget);
        FileOutputStream jasperOutput = new FileOutputStream(compileTarget);

//      compile the report
        JasperCompileManager.compileReportToStream(jrxmlInput, jasperOutput);

//      lol

    }
}

How can I find this file at the root of my source directory?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:25:58+00:00Added an answer on May 27, 2026 at 3:25 pm

    When Maven packages that up it will put it in the .jar of the project it won’t be accessable as a File anymore.

    It can be accessed as a Stream with

        JasperReportsApplication.class.getResourceAsStream("/sampleReport.xml")
    

    This file should actually be in the src/main/resources directory instead of the src/main/java directory to follow Maven conventions, that is to say it isn’t Java source code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty simple Linq to XML query: var q = from c
This question should be pretty simple. I have a php file in a directory
I have pretty simple jquery code : $(document).ready(function(){ $('img.marqFl').on({ mouseenter: function() { $(this).animate({height: 300},
i have pretty simple simple question (i hope so). How do i change the
I have a pretty simple trigger: CREATE OR REPLACE FUNCTION f_log_datei() RETURNS TRIGGER AS
I have a pretty simple ASP.NET Web Form that looks a bit like the
I have a pretty simple SQL I need to perform. I have a ProcessUser
I have a pretty simple question which perhaps someone familiar with Server/Client design &
I have a pretty simple problem. Basically I have an array called $list that
I have a pretty simple case which I started solving using foreach(), but then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.