Closed Thread
Results 1 to 3 of 3

Thread: Why wouldn't a copy of the jar file work?

  1. #1
    sourlemon's Avatar
    sourlemon is offline Programmer
    Join Date
    Nov 2008
    Posts
    101
    Rep Power
    0

    Why wouldn't a copy of the jar file work?

    Hi guys, I'm trying to dynamically load a class. But I'm having trouble with the jar file. This is a snippet of my my code:

    Code:
        File jarFile = null;
        URL url = null;
        try {
                String path = "C:\\Users\\Orange\\Documents\\Lab5\\RpcServer\\MaxMin.jar";
                jarFile = new File(path);
                url = new URL("file", null, -1, jarFile.getAbsolutePath());
                URLClassLoader classLoader = new URLClassLoader(new URL[] {url});
            return classLoader.loadClass("nhu.lab5.maxmin.MaxMinImpl").newInstance();
    That doesn't work. But if I replace the path to where the original file is at, it works fine.

    Code:
        File jarFile = null;
        URL url = null;
        try {
                String path =  "C:\\Users\\Orange\\Documents\\Lab5\\MaxMin\\dist\\MaxMin.jar";
                jarFile = new File(path);
                url = new URL("file", null, -1, jarFile.getAbsolutePath());
                URLClassLoader classLoader = new URLClassLoader(new URL[]  {url});
            return  classLoader.loadClass("nhu.lab5.maxmin.MaxMinImpl").newInstance();
    I'm sure I copy the exact same file, but I don't understand why the first code would work but the second one doesn't. Help?

    Thank you in advance.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Why wouldn't a copy of the jar file work?

    It looks like your jar files is part of a package, which means the .class files MUST be in the correct folder.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    sourlemon's Avatar
    sourlemon is offline Programmer
    Join Date
    Nov 2008
    Posts
    101
    Rep Power
    0

    Re: Why wouldn't a copy of the jar file work?

    You're awesome. Thank you!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copy file
    By stevie754 in forum JavaScript and CSS
    Replies: 2
    Last Post: 03-10-2011, 12:28 PM
  2. [NetBeans] How to save a copy of a file
    By Alhazred in forum General Programming
    Replies: 0
    Last Post: 05-21-2010, 12:27 AM
  3. Replies: 3
    Last Post: 01-26-2010, 08:02 AM
  4. Can't copy file
    By Jaan in forum PHP Development
    Replies: 8
    Last Post: 12-26-2009, 02:03 AM
  5. help copy file?
    By softvnn in forum C and C++
    Replies: 1
    Last Post: 09-02-2008, 08:18 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts