How to get the files in the target/xxx generated by idea compilation

  • directory structure

  • pom

  • target

target

if you do not configure the build location under the resource folder, the test.toml is in target/classes, with the .class file

public class ReadToml {

    public static void main(String[] args) {
        String fileName = "/test.toml";
        File file = new File(ReadToml.class.getResource(fileName).getFile());
        //Toml toml = new Toml().read(file);
    }
}

read it in the way above, and get the path of test.toml
now that build is configured, how can the file in the resources folder get its URL -!

Mar.03,2021

  • create a new directory under resources, such as conf, test.toml and put it under conf
  • you don't need to specify that targetPath, is in the root directory by default
 <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.toml</include>
                </includes>
            </resource>
        </resources>
    </build>
  • in the end, under target, the class files should all be under class/com, and the resource files should be under targate/classes. So String fileName = "/ conf/test.toml" is fine
Menu