0

I have a SOAP Web service that I extract from .wsdl with wsimport

Now, when opening generated file, I have file:// reference that I would need to remove.

I moved WSDL to src/main/resources/Services/RecherchePoint-v2.0.wsdl

But now, I have several references I don't know how to update:

@WebServiceClient(name = "RecherchePointV2.0", targetNamespace = "http://www.enedis.fr/sge/b2b/services", wsdlLocation = "file:/home/ubuntu/wsdl/Services/RecherchePoint/RecherchePoint-v2.0.wsdl")

...

static {
        URL url = null;
        WebServiceException e = null;
        try {
            url = new URL("file:/home/ubuntu/wsdl/Services/RecherchePoint/RecherchePoint-v2.0.wsdl");
        } catch (MalformedURLException ex) {
            e = new WebServiceException(ex);
        }
        RECHERCHEPOINTV20_WSDL_LOCATION = url;
        RECHERCHEPOINTV20_EXCEPTION = e;
    }

I tried changing:

file:/home/ubuntu/wsdl/Services/RecherchePoint/RecherchePoint-v2.0.wsdl"

to

../../../resources/wsdl/Services/RecherchePoint/RecherchePoint-v2.0.wsdl"

but it is not working.

Any idea how to change it ?

Juliatzin
  • 18,455
  • 40
  • 166
  • 325
  • 1
    Possible duplicate of [How do I load a file from resource folder?](https://stackoverflow.com/questions/15749192/how-do-i-load-a-file-from-resource-folder) – Vitalii Vitrenko Oct 24 '19 at 16:49

2 Answers2

1

You can use org.springframework.core.io.ClassPathResource

/**
 * {@link Resource} implementation for class path resources. Uses either a
 * given {@link ClassLoader} or a given {@link Class} for loading resources.
 *
 * <p>Supports resolution as {@code java.io.File} if the class path
 * resource resides in the file system, but not for resources in a JAR.
 * Always supports resolution as URL.
 *
 */

new ClassPathResource("Services/RecherchePoint-v2.0.wsdl")

Here some explanation.

earandap
  • 1,446
  • 1
  • 13
  • 22
0

you can place the file in Resources and you can use the class loader to get the file

ClassLoader classLoader = getClass().getClassLoader();  
File file = new File(classLoader.getResource("RecherchePoint-v2.0.wsdl").getFile());