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

[Request] Classpath Resources #56

Open
danthe1st opened this issue Nov 2, 2023 · 0 comments
Open

[Request] Classpath Resources #56

danthe1st opened this issue Nov 2, 2023 · 0 comments

Comments

@danthe1st
Copy link
Contributor

danthe1st commented Nov 2, 2023

A common source of confusion among (somewhat) new Java developers (especially when they are packaging their first application as a JAR) is resources on the classpath and how they are different from files.

I would request an article clarifying these things, specifically the following:

  • What's the difference between resources and files?
  • When I access a file in my source folder using java.io.File (or similar), why does it not work in a JAR deployed somewhere (in a different directory, on a different computer, ...)
    • Why should I not use files for accessing anything in the source folder?
  • What does Class#getResource/Class#getResourceAsStream do?
  • What's the difference between getClass.getResource("a.txt"), getClass().getResource("/a.txt") and getClass().getClassLoader().getResource("a.txt")?
    • Why does it not find my resource when I use the wrong one?
  • Where should I put resources?
    • with Maven/Gradle but also in plain Eclipse/IntelliJ/VSC projects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant