Questions tagged [getresource]

283 questions
4
votes
3 answers

class.getResource(".") returns null

I am using wsimport in a web service client project to generate artifact classes based on wsdl files. I am trying to reference locally the wsdl files, by using wsdlLocation attribute. The generated services will try to create an URL based on the…
Alina
  • 121
  • 9
4
votes
2 answers

How should I use getResource() in Java?

This question is asked in numerous places, with myriad small variations. (Such as Java - getClassLoader().getResource() driving me bonkers among others.) I still can't make it work. Here's a code snippet: String clipName = "Chook.wav"; …
Chap
  • 3,649
  • 2
  • 46
  • 84
4
votes
2 answers

Getting a resource in a different project using classloader

Using the ClassLoader#getResource(), I need to access a file that is present in a project other than the one where my current code resides. How can this be done? I'm using eclipse. Directory Structure: Root |-project1 | |-package | …
Unknown
  • 41
  • 1
  • 2
4
votes
0 answers

getResource not work with jar running in docker

I put qqwry.dat in src/main/resource in my SpringBoot project. In my class, I tried: IPSeeker.class.getResource("/qqwry.dat"), IPSeeker.class.getClassLoader().getSystemResource("qqwry.dat") Both is OK running on my own computer with tomcat embebed…
wpp
  • 161
  • 1
  • 1
  • 7
4
votes
1 answer

Proper path for using ClassLoader.getResource()?

I've made a function(Java) that is supposed to read bytes from a file and print them to the console: public void loadPixels(int size){ ClassLoader cl = this.getClass().getClassLoader(); pixels = new byte[size]; try{ InputStream…
user2649681
  • 750
  • 1
  • 6
  • 23
4
votes
2 answers

getResourceAsStream in dynamically loaded jar

I kow there are dozens (if not hundreds) questions about Java's getResource/getResourceAsStream but i did not find any answers to my problem. I load jars dynamically with: (String path is given) File jar = new File(path); URL url = new URL("file",…
moschn
  • 68
  • 5
4
votes
1 answer

Dynamically load a class as byte array with ClassLoader in Android

I Am trying to load a class as a byte array so I could send it over the network and execute it remotely via Reflection. This Class (Bubble in this case) is in the same package. The thing is that I can't get the resource using the…
4
votes
1 answer

Trying to load image using ImageIO.read(class.getResource(URL)) but getResource is returning null

I've been making a 2D game with my buddy and I've been learning a lot about some basic game dev concepts through some Youtube tutorials. One of the things I was learning about is sprites (for those that don't know, 2D images to render to the screen)…
user2466959
  • 41
  • 1
  • 1
  • 2
4
votes
1 answer

Caching sounds using byte arrays from within jar file

I can read and play sounds using the "Playing a Clip" solution from the javasound tag wiki page. However, for sounds that are played frequently (e.g., a quick laser gun sound, a footstep, etc.), it's jarring to me to be opening streams and…
wchargin
  • 15,589
  • 12
  • 71
  • 110
3
votes
1 answer

FileNotFoundException. Works and doesn't work at the same time?

I have the following code in a static class called Methods that is archived in a jar: System.out.println(Methods.class.getResource("tagdict.txt")); // 1 URL test = Methods.class.getResource("tagdict.txt"); //…
3
votes
2 answers

Load all files from directory using .getClassLoader().getResource()

In one of my JUnit tests, I am trying to load all the files contained in a directory. I used .getClassLoader().getResource("otherresources") to find the directory. I then made a new java.io.File. I then used listFiles() to get all the children files…
Arun V
  • 590
  • 6
  • 20
3
votes
2 answers

getResource() to a file at runtime

I put some .txt files under the src folder (in the resources folder). But I can't create a valid File at runtime from this resource. String path = this.getClass().getResource("/resources/file.txt").getFile(); File file = new File(path); if…
kenny
  • 2,000
  • 6
  • 28
  • 38
3
votes
1 answer

Java class.getRessource().getPath() adds a weird '/' at the begining of the URL

I want to load a font in a SWT. My ttf file is in the resources/fonts directory of my Maven project. I try to load it like this: URL fontURL = MyClass.class.getResource("/fonts/myfont.ttf"); boolean fontLoaded =…
Gaëtan
  • 779
  • 1
  • 8
  • 26
3
votes
1 answer

JavaFX loading CSS style from resources folder

Project Structure: I'm currently developing a JavaFX application in Eclipse and I'm having trouble loading a .css stylesheet from the resources folder. I've already added the resources folder to the classpath (Project Properties -> Source -> Add…
Franch
  • 621
  • 4
  • 9
  • 22
3
votes
1 answer

Incorrect path to recsource file using Jenkins

I'm using a file from resources dir, calling it using the code: XmlDataLoader.class.getClassLoader().getResource("testData").getPath() It works well on my local machine and the path to the file is correct:…
Bohdan Nesteruk
  • 794
  • 17
  • 42
1 2
3
18 19