getResourceAsStream null on stream - java

I've looked around the web for quite some time without getting a answer that works.
So my issue is that I cannot load the stream of my image.
My Code as to test it:
System.out.println(Main.class.getResourceAsStream("AQUA_KINGDOM.png"));
System.out.println(Main.class.getResourceAsStream("/img/AQUA_KINGDOM.png"));
System.out.println(Main.class.getResourceAsStream("img/AQUA_KINGDOM.png"));
System.out.println(Main.class.getResourceAsStream("conquest/img/AQUA_KINGDOM.png"));
System.out.println(Main.class.getResourceAsStream("/conquest/img/AQUA_KINGDOM.png"));
System.out.println(Main.class.getResourceAsStream("kingconquest/conquest/img/AQUA_KINGDOM.png"));
System.out.println(Main.class.getResourceAsStream("/kingconquest/conquest/img/AQUA_KINGDOM.png"));
System.out.println(Main.class.getResourceAsStream("/eu/kingconquest/conquest/img/AQUA_KINGDOM.png"));
And this is my content tree:
They all return null
Additional information:
I am using Eclipse neon(Latest stable)
I also forgot to mention that this is a plugin (exports as a "jar file")
*Plugin for minecraft spigotAPI for those interested

Try using ClassLoader like this:
Main.class.getClassLoader().getResourceAsStream("AQUA_KINGDOM.png");

Related

How do you log all the compiler options being used by Gradle?

I'm using Gradle 7.4.2. I'm trying to see what it uses for generatedSourceOutputDirectory (among other CompileOptions.
I've tried:
tasks.compileJava {
println(options.generatedSourceOutputDirectory.toString())
}
but this prints an unhelpful:
task ':lib:compileJava' property 'options.generatedSourceOutputDirectory'
Sleuthing around the code itself on Github, I see that's its defaults are (seemingly) mangaged via XML code here.
How can I see what the current compile options are?
The option generatedSourceOutputDirectory is of type DirectoryProperty; therefore, to get the value that it holds, you need to call get().

Strange error with changed class name in Java

I am using kryo lib to serialize objects. I get error:
Unable to find class: java.util.ArrayLisoSerialization
and teammates reproduce that error... It seems that java class name from Kryo was changed (ArrayListSerialization -> ArrayLisoSerialization). That was tested at 2 computers (linux and windows, both jdk7) and problem appears only on my computer (linux). I tried to change Java version from jdk7 (build 67) to jdk8, but problem still appears.
Any ideas why it happens?
Bigger part of error trace:
com.esotericsoftware.kryo.KryoException: Unable to find class: java.util.ArrayLisoSerialization trace:messages at com.esotericsoftware.kryo.util.DefaultClassResolver.readName(DefaultClassResolver.java:138) at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass(DefaultClassResolver.java:115) at com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:666) at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:99) at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:528) at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:682)...
That looks like a typo somewhere in kryo or in a configuration file in your project.
I would do a string search on your project file first.
On second glance, this is going wrong:
String className = input.readString();
....
type = Class.forName(className, false, kryo.getClassLoader());
The problem is in your data it sees. Your serialized content contains, as className, the wrong class you mention.
I don't know how this could've been caused to write like this, as I would assume that a java.util.ArrayListSerialization was originally written but got corrupted somehow.
I'm not too familiar with Kryo however. Is this written to a human readable text file? if so this might've been an accidental replacement while reading the file by hand. (with vi, notepad, or something else). From what I can see, the inputstream is simply read, and a string is opened.
I would open the data file and see if the string java.util.ArrayLisoSerialization is present there.
I assume this should be changed to java.util.ArrayListSerialization.
HOWEVER make a backup of any data you are modifying. Changing serialized data should always be done with the safety of being able to revert back to the original data.

W3C css-validator.jar: Where do I find documentation about local usage (parameters, etc.)?

I successfully installed W3C css-validator.jar locally as described here:
How can I validate CSS on internal web pages?
Now I'm looking for some documentation about how to use it.
At the moment I'm doing something like this:
java -jar css-validator.jar --output=soap12 file:source.css > result.xml
I'd like to accomplish the following:
Output in a different format, e.g. XML (I guess that I can simply do --output xml for this)
Input a string directly without a file, e.g. string:"body { color: red; }"
Output the result directly without a file (so not like > result.xml) so I can do something like RESULT = java -jar css-validator.jar...
I didn't find a lot of information about this, but at least here are some configuration parameters:
http://jigsaw.w3.org/css-validator/manual.html

Purpose and usage of "application.path" variable

In the Play! framework source for the main method in Server.java I found these two lines:
File root = new File(System.getProperty("application.path"));
if (System.getProperty("precompiled", "false").equals("true")) {
Play.usePrecompiled = true;
}
Where can I find the application.path value?
System.getProperty("application.path") that looks like a -D property. So at the start of the server there is a call like
java -Dapplication.path=/opt/play/myApp
/play/framework/pym/play/application.py in line 251 makes the work.
There might be a properties file in your application and also there might be a mechanism to load all those properties into System properties.
Search for application.path in your application folder file contents and you may get a clue.
It may be in your application.conf file. Check there.

Dumping java.lang.Class's originated from jar files

I am trying to find a way to collected all java.lang.Class's loaded from jar files but ignore the ones from the source code itself.
I have found java.lang.instrument.Instrumentation interface and thought it might serve the purpose, but it turned out not quite.... One of the available functions "getAllLoadedClasses" dump all java.lang.Class's out (which is good), but it not only dump onces got loaded from jar file and also loaded from the source file.
Is there a configuration that allows us to customize the setting so only the java.lang.Class's originated from jar files are dumped or there is better solution in the wild?
What I want to achieve in code representation will be something like below.
java.lang.Class[]
classesLoadedFromJars = getClassesLoadedFromJars();
for (java.lang.Class class : classesLoadedFromJars) {
// ..............
}
A word or two on the suggestion will be helpful!
Thanks in advance.
The class's classloader should be able to give you a clue as to where a certain class was loaded from.
ClassLoader loader = myClass.getClassLoader()
if (loader instanceof URLClassLoader) {
URLClassLoader uLoader = (URLClassLoader)loader;
URL cURL = uLoader.getResource(myClass.getName().replace('.', '/')+".class");
}
if cURL starts with jar:// , the class originated from a jar file

Categories

Resources