3

I have a quick question about altering the build path as the code is running.

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

gprathour
  • 14,813
  • 5
  • 66
  • 90
MrDrProfessorTyler
  • 403
  • 2
  • 10
  • 26

1 Answers1

2

Some suggested amendments / comments:

  • Remove the jar: prefix and the !/ suffix - these are note required and are probably confusing the matter
  • Can you verify the jar file exists:

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

  • Amend your class declaration to the following (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 example, using commons-codec as the jar, and loading the Base64 class

Chris White
  • 29,949
  • 4
  • 71
  • 93