Search code examples
filejarpathlocalrunnable

runnable JAR: local path issue


I want to export my project to a runnable JAR (in Eclipse). But I have a Code-Section with a local path! How can I avoid the local path problem?

Thank you very much for helping me.

static {
    URL url = null;
    WebServiceException e = null;
    try {
        url = new URL("file:/C:/myWorkspace/myProject/folder/data.wsdl");
    } catch (MalformedURLException ex) {
        e = new WebServiceException(ex);
    }
    APISERVICE_WSDL_LOCATION = url;
    APISERVICE_EXCEPTION = e;
}

Solution

  • Very simple. Use a relative path URL. It is always a better practice to keep your files under src/main/resources directory and access via this.getClass().getResourceAsStream()