Use a dependency's resources?

前端 未结 5 857
死守一世寂寞
死守一世寂寞 2020-12-01 09:09

In my Maven project there is one module (core) that has a few resources for its classes. When running classes inside the module its able to get its own resources. Everything

5条回答
  •  爱一瞬间的悲伤
    2020-12-01 09:45

    If the resources are located in /src/main/resources and classes in the JAR are accessing them using getResourceAsStream(), you should be able to access these files from classes in other JARs as well (also using getResourceAsStream()). This is because all the files located in /src/main/resources eventually land in the same logical directory (CLASSPATH). In other words: all the files located in /src/main/resources and all the classes compiled from /src/main/java are so to say merged into a single namespace.

    If you still can't access files even though all the classes are using uniform getResourceAsStream() API, you might have some class-loading visibility issues.

提交回复
热议问题