Text file placed in resources in Java cannot be read when jarted

I cannot refer to the resource when it is made into a jar.

    1. Create a Maven project in Eclipse. (I don't think it's particularly related to Maven)
  1. Create a folder under src / main / resources and place the text file.

    1. Create a process to read resources and perform System.out.println.

In such a situation, when I execute it from Eclipse, the contents of the text file are output correctly, but when I export it to a jar with Eclipse and execute it, it cannot be referenced and an exception occurs.

■ It is an image of the execution result that the contents defined in Eclipse and the contents of File1.txt are output after test execution. image.png

■ It is an image when a Null reference exception occurs when executing after checking the contents of the Jarized file and confirming that File1.txt is included. image.png

There may be a setting to refer to the resource correctly in the jar state, or there may be a problem with the logic, but it is a situation where you can not get a clue.

Could you please tell me if there are any possible problems?

Recommended Posts

Text file placed in resources in Java cannot be read when jarted
[Java] Read the file in src / main / resources
Easily read text files in Java (Java 11 & Java 7)
Read Java properties file in C #
Read xlsx file in Java with Selenium
Read a string in a PDF file with Java
[Swift5] Problem that Cell cannot be tapped when TextView is placed in TableViewCell
Read JSON in Java
Read Java Property file
[Java] Integer information of characters in a text file acquired by the read () method
How to read your own YAML file (*****. Yml) in Java
Things to be aware of when writing code in Java
Read binary files in Java 1
Cannot find javax.annotation.Generated in Java 11
Read standard input in Java
Read binary files in Java 2
Java Stream cannot be reused.
[Java] [Android] Read ini file
Symbol not found error when new class in another Java file
"ClassNotFoundException" is displayed when tomcat is started in eclipse and cannot be started
Note that system properties including JAXBContext cannot be used in Java11
Read items containing commas in a CSV file without splitting (Java)
Sample to read and write LibreOffice Calc fods file in Java 2021
<java> When "EXCEPTION_ACCESS_VIOLATION" appears in awt
Read CSV in Java (Super CSV Annotation)
Unzip the zip file in Java
Log output to file in Java
Include image resources in jar file
Measures when model cannot be created
About file copy processing in Java
Java cannot be installed on Ubuntu 13.04
When you get LoadError (cannot load such file --ruby_file) when you require in Ruby
How to read log4j configuration file in Java project summarized in jar file Memo
When calling println etc. from an external Java class file in Processing