getResourceAsStream gets the time null pointer exception

tags: Common problems  java  spring boot  jar

background:

I have written a springboot+testng project. The project needs to be run through the mvn test command, but the getResourceAsStream method has been reporting errors and cannot run

At that time, in order to run the java -jar command and make the configuration dynamic, my project moved the propeties file at the same level as the src directory.

So my project structure is:

The properties file is placed in the properties directory

The resources directory is placed in the file that needs to be read in my code, that is, the resource file read by getResourceAsStream

The xml directory is the configuration xml file for the use case I need to run.

Question points:

When I run through the mvn test command, I have an exception directly in the code below and the test cannot continue

Solution:

In idea

Through online search, this piece of resource acquisition cannot be obtained. It may be because the source (source) configuration in the project is incorrect. Enter the project structure configuration from the file

You can add the directory you need to compile to Source Folders by clicking Sources after selecting it.

 

After the modification is completed, the project is recompiled and then runs and runs, but it is just in idea. The real thing about this project running on jenkins is still not OK, and then I continue to dig

jenkins

Through online search, I found that we can change the source of the project by configuring the pom file. The main use is the build-helper-maven-plugin plugin. We can add the source directory we need to add in the source tag.

Actually, I took the above step and it would be fine to recompile it. However, my original operation dug a hole for myself, that is, I configured the resources tag in the pom before, which is the following configuration. This is because of this, the files under resources cannot be released when I packaged, and I was very desperate. When I remembered that when I checked this problem, my colleague reminded me to type out the address of the file, and then I printed out the address of the file, and then went to the directory to read it, and found that the folder under json had not been generated. . .

The command to take out the currently placed file directory address is: class name.class.getClassLoader().getResource("").getPath();

Then I removed the resources configuration in the pom and it was OK. The problem that has tortured me for a long time is still not enough. Record it. Next time, record the process of running the test project using the java -jar command before

 

 

Intelligent Recommendation

searchView null pointer exception

The following problem occurs when adding a listen event to the SearchView Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.support.v7.widget.SearchView.s...

News null pointer exception

     ...

Null pointer exception summary

1: NullPointerException is derived from RuntimeException out, is a level of abnormal operation. Meaning that could only be thrown at run time, and need to see whether this will lead to abnormal levels...

Null pointer exception (a)

News null pointer exception Log in to point out an error seatreturn Application.get().getString(R.string.gps_status_tab); And then tracking problem isApplication.get() Is null, then the Application is...

Null pointer exception NullPointException

Null pointer exception NullPointException Null pointer exception is an exception, there was a null pointer when writing code in time runtime exceptions, the compiler (javac) compiler will not be given...

More Recommendation

mybatis null pointer exception

mybatis null pointer exception 1. When an entity type is passed, and the entity class with the sql Integer id, when an incoming new class when the entity not being given, then id = null; and to return...

Exception: runOnUiThreadkongz null pointer

Error: Error location: analysis: This is because the activity becomes invisible when the thread ends. getActivity () may be empty, need to judge in advance solve:...

Null pointer exception in java

Chain call Especially when chaining a certain attribute, it should be noted that the intermediate node may be empty. It is recommended to use Optional to implement chained calls after java8. 2. Origin...

java.lang.NullPointerException Null Pointer Exception

1. The so-called pointer is a reference to an object in java. For example, String s; this s is a pointer. 2. The so-called null pointer means that the content of the pointer is empty, such as s above,...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top