-2

I am posting this question because I have not been able to understand what I have to do in order to load a resource file from my java project.

the structure is the following one:

enter image description here

and what I want to do is to load boletinoficial.wsdl file in order to get the URL.

I have tried several ways to do that: getClass.getClassLoader.getResource(), getClass.getResource(), with absolute paths, with relative paths. But always getting null or exceptions. I also added src folder to the build path but no success.

Is there any easy way to load that file?

EDIT

ok. and now that I have the structure,

enter image description here

how do I load the resource boletinoficial.wsdl from the class App.java?

CDspace
  • 2,639
  • 18
  • 30
  • 36
bentakayze
  • 131
  • 1
  • 5
  • 12
  • 4
    How do you load the resource? This normally works as intended: `MyCoolClass.class.getResource("/resource.text")` (expects the resource on the path - e.g within `src/main/resources`). Are you sure you're using the correct path definition? – vegaasen Feb 15 '17 at 14:52
  • Many thanks!! It worked!! – bentakayze Feb 15 '17 at 15:42

1 Answers1

8

If you want to load a Resource, you should put them in src/main/resources, as they'd be ignored in src/main/java

DamCx
  • 1,047
  • 1
  • 11
  • 25
  • I have edited my question with the modification u suggested. do yo know how to load boletinoficial.wsdl? – bentakayze Feb 15 '17 at 15:15
  • If the point is to get your wsdl used to generate java classes, you should have a look here : http://stackoverflow.com/questions/18338196/how-to-generate-classes-from-wsdl-using-maven-and-wsimport Otherwise, you should tell me what use you would have from your wsdl – DamCx Feb 15 '17 at 15:18
  • I already created the classes via wsimport from a wsdl file I have. The point is that the service class points to the absolute path of the wsdl file in my computer, and I think this is not good. so I thought to store the wsdl file in the project and when instancing the service, try to find a way to tell the service class to get the wsdl file in the project, not the other one. Not sure if I have explained quite well. – bentakayze Feb 15 '17 at 15:23
  • I'm not sure to see what you mean, because once your objects are generated, you have the classes to call your services, so you don't need to use your wsdl anymore – DamCx Feb 15 '17 at 15:29
  • The thing is your WSDL won't be used when your WAR will be generated, so you won't need it anymore. What you need to be sure of is that your Endpoint will be good – DamCx Feb 15 '17 at 15:34
  • Many thanks for the piece of advice, but do you know the way to load that resource? – bentakayze Feb 15 '17 at 15:36
  • 1
    It has been solved by the way the other contributor said. Many thanks for your knowledge anyway :) – bentakayze Feb 15 '17 at 15:43