Java Build Path

I have a quick question about changing the build path when running the code.

For example, I have a class that downloads a .jar file from the internet and then into the same directory from which the code is executed. How, if possible, can I load the jar into the build path to access the classes in the .jar file?

+3


source to share


1 answer


Some suggested amendments / comments:

  • Remove the prefix jar:

    and suffix !/

    - these are necessary notes and probably confusing the question
  • You can check if the jar file exists:

    System.out.println(new File(new URL("file://test.jar")).exists());

  • Modify the class declaration as follows (get the File object to generate the url for you to avoid problems):

    URL[] classes = new URL[] { new File("test.jar").toURI().toURL() };



This worked for my test case using commons-codec as jar and loading the Base64 class

+2


source







All Articles