Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassLoader.getResources("") return different results, when run in ide/fat jar/exploded directory #9509

Closed
hengyunabc opened this issue Jun 14, 2017 · 2 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@hengyunabc
Copy link
Contributor

Print ClassLoader.getResources("") results in main method:

    public static void main(String[] args) throws IOException {
        Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources("");
        while(resources.hasMoreElements()) {
            System.err.println(resources.nextElement());
        }
        System.err.println("=====");

        SpringApplication.run(DemoApplication.class, args);
    }
  • IDE:
file:/private/tmp/demo/target/classes/
=====
  • Fat jar:
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-boot-starter-web-1.5.4.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-boot-starter-1.5.4.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-boot-1.5.4.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-boot-autoconfigure-1.5.4.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-boot-starter-logging-1.5.4.RELEASE.jar!/
=====
  • Exploded directory:
cd target
unzip demo-0.0.1-SNAPSHOT.jar -d test
cd test 
java org.springframework.boot.loader.PropertiesLauncher
file:/private/tmp/demo/target/test/
file:/private/tmp/demo/target/test/BOOT-INF/classes/
=====
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 14, 2017
@wilkinsona
Copy link
Member

This is by design (see #7003). Is the current behaviour causing a problem?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Jun 14, 2017
@hengyunabc
Copy link
Contributor Author

Some libraries depend on ClassLoader.getResources("") to scan annotations. When run in fat jar, it may scan excess classes.

There is no problem, I just have some doubts, thanks.

@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants