getResourceAsStream returns null

Lifepaths.class.getClass().getResourceAsStream(…) loads resources using system class loader, it obviously fails because it does not see your JARs Lifepaths.class.getResourceAsStream(…) loads resources using the same class loader that loaded Lifepaths class and it should have access to resources in your JARs

What is the JSF resource library for and how should it be used?

Actually, all of those examples on the web wherein the common content/file type like “js”, “css”, “img”, etc is been used as library name are misleading. Real world examples To start, let’s look at how existing JSF implementations like Mojarra and MyFaces and JSF component libraries like PrimeFaces and OmniFaces use it. No one of … Read more

Get OS-level system information

You can get some limited memory information from the Runtime class. It really isn’t exactly what you are looking for, but I thought I would provide it for the sake of completeness. Here is a small example. Edit: You can also get disk usage information from the java.io.File class. The disk space usage stuff requires … Read more

Scala Programming for Android

I’ve written some basic Android applications in Scala, nothing too epic. Not being a Java programmer I was suggested to use a “treeshake”, I was explained by a friend that this strips out all the unnecessary libraries from the jar files. I have not documented it, but I found that someone else already has: http://chneukirchen.org/blog/archive/2009/04/programming-for-android-with-scala.html … Read more

Add floating point value to android resources/values

There is a solution: <resources> <item name=”text_line_spacing” format=”float” type=”dimen”>1.0</item> </resources> In this way, your float number will be under @dimen. Notice that you can use other “format” and/or “type” modifiers, where format stands for: Format = enclosing data type: float boolean fraction integer … and type stands for: Type = resource type (referenced with R.XXXXX.name): … Read more

Get a list of resources from classpath directory

Custom Scanner Implement your own scanner. For example: (limitations of this solution are mentioned in the comments) private List<String> getResourceFiles(String path) throws IOException { List<String> filenames = new ArrayList<>(); try ( InputStream in = getResourceAsStream(path); BufferedReader br = new BufferedReader(new InputStreamReader(in))) { String resource; while ((resource = br.readLine()) != null) { filenames.add(resource); } } return … Read more

Reading a resource file from within jar

Rather than trying to address the resource as a File just ask the ClassLoader to return an InputStream for the resource instead via getResourceAsStream: try (InputStream in = getClass().getResourceAsStream(“/file.txt”); BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { // Use resource } As long as the file.txt resource is available on the classpath then this approach will … Read more

What’s the difference between StaticResource and DynamicResource in WPF?

A StaticResource will be resolved and assigned to the property during the loading of the XAML which occurs before the application is actually run. It will only be assigned once and any changes to resource dictionary ignored. A DynamicResource assigns an Expression object to the property during loading but does not actually lookup the resource … Read more

Should a RESTful ‘PUT’ operation return something….

The HTTP specification (RFC 2616) has a number of recommendations that are applicable. Here is my interpretation: HTTP status code 200 OK for a successful PUT of an update to an existing resource. No response body needed. (Per Section 9.6, 204 No Content is even more appropriate.) HTTP status code 201 Created for a successful … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)