I'm aware there are several other questions regarding this...
- Class.getResource() returns null
- Java - class.getResource returns null
- Calling context.getResources() returns null
- getClassLoader().getResource(filepath) returns a null pointer
But my problems seems to be a bit different because I seem to have all of the necessary things to NOT have this problem.
The code:
this.getClass().getResource("checkstyle_whitespace.xml"); // null
The issue is that I've verified my classpath by inspecting the class loader in the debugger. Here's what I am seeing:
27 = {URL@1235} "file:/Users/dennis/Documents/Development/java/java-grader/build/classes/main/"
28 = {URL@1236} "file:/Users/dennis/Documents/Development/java/java-grader/build/resources/main/"
Blow is a quick tree
of my directory structure. See build/resources
and src/main/resources
. The files are being copied when gradle builds my project.
├── build
│ ├── classes
│ │ ├── main
│ │ │ └── javaGrader
│ │ └── test
│ │ └── javaGraderTest
│ └── resources
│ └── main
│ ├── checkstyle_whitespace.xml
│ └── grammars
├── src
│ ├── main
│ │ ├── java
│ │ │ └── javaGrader
│ │ └── resources
│ │ ├── checkstyle_whitespace.xml
│ │ └── grammars
│ └── test
│ ├── java
│ │ └── javaGraderTest
│ └── resources
│ └── mini_test
├── target
│ ├── classes
│ ├── generated-sources
│ │ └── annotations
│ └── generated-test-sources
│ └── test-annotations
└── test_assets
From what I understand, the files should be accessible because they're in build
. Correct me if I am wrong...