- Open Windows Explorer.
- On the left part of the screen, select the Computer icon.
- Right-click this icon and select properties.
- A window will open, select Advanced System Settings.
- A System Properties windows will open.
- At the bottom, click Environment Variables.
Tips & Tricks, Summaries, Check Lists, Do's & Don'ts, Reminders, Stuff that works...
Showing posts with label Path. Show all posts
Showing posts with label Path. Show all posts
Sunday, 16 September 2012
Accessing Environment And System Variables On Windows 7
This is a reminder describing how to access environment and system (including path) variables under Window 7:
Thursday, 2 August 2012
Understanding Absolute and Relative Path with getResourceAsStream()
Not making the difference between absolute and relative paths when loading resources in Java is a common source of errors leading to NullPointerException (NPE).
Assuming the following structure and content in a maven project:
Content will be re-organized as following in the .jar:
The following indicates what works and what does not work to retrieve resource data:
getResourceAsStream() operates relative to the package corresponding to the called Class instance.
Assuming the following structure and content in a maven project:
My Project
|-src
|-main
|-java
|-src
|-main
|-java
| |-SomePackage
| |-SomeClass.java
|-resources
|-Root.txt
| |-SomeClass.java
|-resources
|-Root.txt
|-SomePackage
|-MyData.txt
|-SomePackage2
|-MySubData.txt
|-MyData.txt
|-SomePackage2
|-MySubData.txt
Content will be re-organized as following in the .jar:
|-Root.txt
|-SomePackage
|-SomeClass.java
|-MyData.txt
|-SomePackage2
|-MySubData.txt
|-SomeClass.java
|-MyData.txt
|-SomePackage2
|-MySubData.txt
The following indicates what works and what does not work to retrieve resource data:
InputStream IS; IS = SomeClass.class.getResourceAsStream( "Root.txt"); // Not OK IS = SomeClass.class.getResourceAsStream( "/Root.txt"); // OK IS = SomeClass.class.getResourceAsStream( "/MyData.txt"); // Not OK IS = SomeClass.class.getResourceAsStream( "MyData.txt"); // OK IS = SomeClass.class.getResourceAsStream( "/SomePackage/MyData.txt"); // OK IS = SomeClass.class.getResourceAsStream( "SomePackage/MyData.txt"); // Not OK IS = SomeClass.class.getResourceAsStream( "MySubData.txt"); // Not OK IS = SomeClass.class.getResourceAsStream( "SomePackage/SomePackage2/MySubData.txt"); // OK IS = SomeClass.class.getResourceAsStream( "/SomePackage/SomePackage2/MySubData.txt"); // Not OK IS = SomeClass.class.getResourceAsStream( "/SomePackage2/MySubData.txt"); // Not OK IS = SomeClass.class.getResourceAsStream( "SomePackage2/MySubData.txt"); // OK
getResourceAsStream() operates relative to the package corresponding to the called Class instance.
Subscribe to:
Posts (Atom)