Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Can class definitions for a single package be spread across several JARs?

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can class definitions for a single package be spread across several JARs?

    Can I put some class definitions for some extensions to a package in a different JAR file, without making it a different package?

    My reason for wanting to do this is that I'm trying to write some extensions to a package written by someone else. He and I both frequently issue new versions, and it would be much easier when he produces a new version if all I or other users had to do was copy his new JAR file into their application directory. If I'm only allowed to use a single JAR file, then I have to rebuild the whole application every time he produces an update.

    Is this a good reason for having a package in multiple JAR files?

    Is there a better way of achieving what I'm trying to achieve?

    Thanks - Rowan


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,324
    My Mood
    Hungover
    Thanks
    142
    Thanked 624 Times in 535 Posts

    Default Re: Can class definitions for a single package be spread across several JARs?

    What happened when you tried?

    And why don't you use some kind of version control system?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can class definitions for a single package be spread across several JARs?

    Quote Originally Posted by KevinWorkman View Post
    What happened when you tried?
    Well, I've been struggling to get everything in the right directories and everything named correctly, but I finally think I've found a way of making it work, and the answer seems to be that it works OK. It does successfully find my derived classes in my new JAR file, and treat them as part of the same package that's in the original JAR file.

    Quote Originally Posted by KevinWorkman View Post
    And why don't you use some kind of version control system?
    I do, for the code that I write. And the guy who wrote the original application uses one too, that I have read only access to. But how does this help? I don't particularly want to ask him for full access to his CVS system. He probably would not give it to me, and in any case I'm not sure I want to expose my beginner's efforts to him at this stage...

    Anyway, it seems to be working, so I seem to have answered my own question. If you know of a better or more elegant way of achieving this (it's effectively extending the functionality of a package without the need to modify or rebuild the original at all, and potentially without even the need to have the source code of the original) please let me know.

    Thanks - Rowan

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,324
    My Mood
    Hungover
    Thanks
    142
    Thanked 624 Times in 535 Posts

    Default Re: Can class definitions for a single package be spread across several JARs?

    Some issues you might want to consider- what if both Jars contain the same class name in the same package? What if an expected class is removed from one of the Jars?

    I'm not sure your goal of extending a package like that is best (what's so wrong with using your own package?), but only you know your specific context, so it's up to you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can class definitions for a single package be spread across several JARs?

    Quote Originally Posted by KevinWorkman View Post
    What if both Jars contain the same class name in the same package? What if an expected class is removed from one of the Jars?
    Well, I will be careful not to duplicate a classname that's used in the "original" package. In any case I would immediately find this out when I tested the solution. If the original developer by coincidence adds a classname to his application which duplicates one I've already created, my version of the app will stop working, and I'll just have to fix it if this happens. Not ideal, I know, but a fairly remote chance in this particular case, so one I will live with.
    Quote Originally Posted by KevinWorkman View Post
    what's so wrong with using your own package?
    Well, the package name is hard coded into his part of the application, so if I use a different one (that's what I tried first) my code never gets called. That's what led me to ask this question in the first place.

    Anyway, thanks for your interest and help. I've learnt something, and my solution is working so progress has been made!

    Rowan

Similar Threads

  1. Simple package problem, package does not exist error
    By Farmer in forum Object Oriented Programming
    Replies: 3
    Last Post: August 23rd, 2011, 11:18 AM
  2. Replies: 1
    Last Post: June 13th, 2011, 07:02 PM
  3. Replies: 3
    Last Post: April 11th, 2011, 09:51 PM
  4. OS Specific Jars
    By sinistaDev80 in forum Java Theory & Questions
    Replies: 0
    Last Post: March 26th, 2011, 09:29 AM
  5. Programmatically Creating Jars
    By aussiemcgr in forum Java Theory & Questions
    Replies: 8
    Last Post: October 6th, 2010, 11:51 AM