亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

java - Maven項目里,Junit的test程序不能直接訪問src/test/resource里的文件?
迷茫
迷茫 2017-04-18 10:39:41
0
2
581
迷茫
迷茫

業(yè)精于勤,荒于嬉;行成于思,毀于隨。

reply all(2)
大家講道理

If you want to obtain example.xml, you can use the following 2 methods

AppTest.class.getResource("/example.xml");
AppTest.class.getClassLoader().getResource("example.xml");

JavaResource path

File file path

  1. path starts with /開頭則是指向磁盤根目錄。如/usr/local/bin/xxx則是指向根目錄中/usrdirectory

  2. The path starting with the file (folder) name is relative to the file in the user.dir directory. For example, the file actually pointed to by user.dir目錄下的文件。如example.xml實際指向的文件是System.getProperty("user.dir") + "example.xml" is the System.getProperty("user.dir") + "example.xml" file

CLASSPATH resource path

CLASSPATH resources have class.getResource()classLoader.getResource()two ways to obtain

  1. If Test.class.getResource()資源是以/開頭則指向CLASSPATHroot directory

  2. If Test.class.getResource()是以文件(包名)開頭則相對Test.classfile is located in packagefind resource

  3. Test.class.getClassLoader().getResource()是以CLASSPATHLooking for resources in the root directorycan only start with a file (package name)

PHPzhong

I also encountered your problem the day before yesterday. The solution is: File-Project Structure in the menu bar. Select Moudles in the opened interface. If you see the attached picture, you can use the configuration file under the normal solution resource.

Then add under the build tag of pml.xml file:

<resources>
            <!--表示把java目錄下的有關xml文件,properties文件編譯/打包的時候放在resource目錄下-->
            <resource>
                <directory>${basedir}/src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
            </resource>
        </resources>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template