-1

I noticed that a minecraft server loads in external jar files. I would like to use this to create a hub to load small games into. I want to do this by calling a method in a group of jar files to load them. Is this possible without executing it directly or modifying the classpath. I'm using the following code to start and load the hub:

EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Window window = new Window();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }); 

Now I will run a loop for the number of jar files in a folder. I will store these in an array. Then I want the action for the button to call a load method from the jar files

Michael Chav
  • 441
  • 5
  • 15
Anthony Sasse
  • 64
  • 1
  • 6

1 Answers1

0
  1. Add the jar to your buildpath of the project, right click the project
  2. Select "Build Path" option
  3. Select "Configure Build Path" and add in the external jar

Once you've configured your buildpath you import the class, create an instance of the class to use whatever method you're looking for. That should be it.

I think you can also do something like this (once it's added to your buildpath), not 100% sure on this one though.

ClassNameFromJarYouWant.MethodYouWant();

That'd be the easiest.

But if you really need to be able to add the JARs without modifying the classpath look up URLClassLoader. Here's a post I found that might help you.

Community
  • 1
  • 1
Grinch91
  • 952
  • 7
  • 15