How to refer to a file present within src/main/resources folder deployed in a jboss env?

前端 未结 2 823
南旧
南旧 2021-01-28 00:09

I need to look up for an image present in src/main/resources folder in a web application. Its an Apache CXF SAOP based web application.

We are

2条回答
  •  旧巷少年郎
    2021-01-28 00:29

    This is my file structure within the Maven project:

    src/main/resources/
    src/main/resources/META-INF
    src/main/resources/adir
    src/main/resources/adir/afile.json
    

    Finally,this worked for me:

    String resourceName = "adir/afile.json";
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    URL resource = classLoader.getResource(resourceName);
    InputStream iStream = resource.openStream();
    byte[] contents = iStream.readAllBytes();
    System.out.println(new String(contents));
    

    HTH, Thomas

提交回复
热议问题