Results 1 to 9 of 9
  1. #1
    unaligned is offline Member
    Join Date
    Jun 2011
    Posts
    23
    Rep Power
    0

    Default Access class files outside of a .jar

    Greetings,

    I have been doing research over the past few days and have so far been unable to find the answer to this question. I am trying to create a modular program where the main UI (core) of the system is included in an executable jar (no problems here).

    The issue is that it needs to dynamically load modules that are added to a lib folder residing in the same directory as the jar when the program is executed (eventually going to turn the jar into a .exe w/ Launch4j). I have so far not been able to do this. It finds the classes just fine (determined by using print statements) but it will not load them into the UI. The file structure of the AP directory is as follows:

    AP.jar (including the package 'core' with all UI components)
    /lib (directory containing the *module.class files representing the modules)

    It works as normal if I include the /lib package/directory in the .jar file, but that defeats the purpose of it being modular so that I can just add new modules to the /lib folder as necessary.

    Has anyone ever done anything like this before? Ideas?

    Thx in advance.
    Last edited by unaligned; 06-06-2011 at 04:46 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    unaligned is offline Member
    Join Date
    Jun 2011
    Posts
    23
    Rep Power
    0

    Default

    I originally had classpath issues (which I posted here and received help to solve). My classpath is currently set to H:/AP. The jar and the /lib directory are both located directly inside of the /AP directory, as noted above.

    Edit:

    I believe the issue is in the fact that the core package expects to find the lib package in the jar, because pre-jaring them they are both in the same directory (H:/AP). This is evidenced because if I include the lib package in the jar file, it works fine. My question is how do I set this up so that it looks for the lib package in the directory where the jar is located instead of inside the jar itself?

    Edit again:

    Further evidence of my idea above is the fact that if I run the class that executes the program via command prompt (not the jar), which is also located in H:/AP, it finds the lib package and loads the modules in the UI as it should.
    Last edited by unaligned; 06-06-2011 at 05:09 PM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    You need to tell the AP.jar (via the MANIFEST) where dependent jars/classes are to be found.
    Executing a jar file strips out the classpath...it only uses the classpath as defined in the jar.

  5. #5
    unaligned is offline Member
    Join Date
    Jun 2011
    Posts
    23
    Rep Power
    0

    Default

    With a line such as 'Class-Path: H:/AP'?

  6. #6
    unaligned is offline Member
    Join Date
    Jun 2011
    Posts
    23
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    You need to tell the AP.jar (via the MANIFEST) where dependent jars/classes are to be found.
    Executing a jar file strips out the classpath...it only uses the classpath as defined in the jar.
    I've been searching extensively for the last couple of hours and have found no reference that says it's possible to add external classes to the Class-Path header that are not in a jar. I need clarification that it is possible. Anyone? And even so, I don't want to have to define in the header each specific class (module) that will be used. This defeats the purpose of the modularity of the program.

    Would the solution to this problem be a custom class loader?

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Have you tried a . for the current folder

  8. #8
    unaligned is offline Member
    Join Date
    Jun 2011
    Posts
    23
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Have you tried a . for the current folder
    Could it really be that simple? Yes, it could. And it works.

    You, sir, are a brilliant man and I am an idiot. Thank you.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    The . works in other contexts, I figured it might there also.

    Glad to know it. I was too lazy to make up a test case, so I let you have the joy of finding out.

Similar Threads

  1. Replies: 0
    Last Post: 04-04-2010, 10:06 AM
  2. how to access and print the dwg files in java
    By vmag in forum Advanced Java
    Replies: 0
    Last Post: 03-19-2010, 06:29 PM
  3. Access remote machine files
    By blueprats in forum New To Java
    Replies: 16
    Last Post: 02-21-2010, 03:13 PM
  4. Random Access Files concept
    By AralX in forum New To Java
    Replies: 2
    Last Post: 12-25-2007, 07:04 PM
  5. access to dll files
    By Heather in forum Advanced Java
    Replies: 1
    Last Post: 07-08-2007, 12:30 AM

Posting Permissions

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