Results 1 to 3 of 3
  1. #1
    frenk_castle is offline Member
    Join Date
    Mar 2010
    Location
    Belgrade, Serbia
    Posts
    27
    Rep Power
    0

    Default Packaging the application into several jar files and class methods

    Question one: I am transferring an application I developed in C++ to Java. Is it possible, and is it a good Java practice, to pack the application in several jar files. Sort of like shared libraries under C/C++. I would like to develop some common classes put them in appropriate packages and then have them in separate jar files so more that one application can use them. To explain in windows terms for not Linux audience I would like to make something like a dll. I am using Java 6 and Eclipse to develop my applications. Is it possible to do what I want and if it is possible is it good Java practice to do so? If answer to these questions is yes is there some documentation on the net how to develop an Java project (projects) like this using Eclipse because I failed to find any.

    Question two: I am using books Core Java volume I and volume II by Cay S. Horstmann and Gary Cornell to get into the Java world. On several occasions the authors are using something that appears to be a method named class. Like this example shows:

    URL url = ResourceTest.class.getResource("about.gif");

    This class method or what ever it is is appearing in lot of seemingly unrelated classes. I googled the net but failed to find what it is, what it does or any information about it.

    Thanks in advance

  2. #2
    Join Date
    Feb 2010
    Location
    Lino Lakes, MN
    Posts
    4
    Rep Power
    0

    Default

    RE: Question #1:
    Basically, what you are asking for is a good idea when you want to reuse code amongst multiple applications. For each jar that you want to create, the simplest way is to create a Java project in Eclipse for each jar that you want to build. You need to open your workspace in Eclipse, then click File | New | Project. Then drill down into the Java folder and choose Java Project and give it a name like CoreUtilities if you are creating a set of classes that would be used as core utilities in multiple applications. From there you would right click the newly created project and chooses New | Package and add your package. For example, you might add a new package named 'com.frenk.core' and another one named 'com.frenk.core.string', etc. Then you will be able to add your classes. Once, you have added your classes, you will then be able to build the jar for your project and use it in other applications. There are a number of videos on YouTube that help explain Eclipse basics, as well as many other resources on the web to help you with any further questions.

    RE: Question #2
    Every class is represented by a corresponding Class object.
    The reference to this object can be obtained using the syntax Class myClass = MyClass.class or by instantiating the class (i.e. MyClass myClass = new MyClass();) and then using the myClass.getClass() method.
    Once you have the class object, you can make use of any of the methods provided by the Class class.

  3. #3
    frenk_castle is offline Member
    Join Date
    Mar 2010
    Location
    Belgrade, Serbia
    Posts
    27
    Rep Power
    0

    Default

    Thank you. I managed to find some tutorials online and managed to do almost all of my application splitting in the way I intended it. Now in will be a lot simpler to maintain my code.

Similar Threads

  1. How can I call abstract class methods from another class
    By srinivas2828 in forum New To Java
    Replies: 13
    Last Post: 03-12-2010, 02:33 PM
  2. packaging files
    By ashish9590 in forum AWT / Swing
    Replies: 2
    Last Post: 02-12-2010, 03:01 PM
  3. Packaging all files into a single executable .jar
    By ichwar in forum New To Java
    Replies: 5
    Last Post: 01-27-2010, 01:31 AM
  4. Using methods and arrays after importing files
    By Jamison5213 in forum New To Java
    Replies: 3
    Last Post: 12-29-2009, 05:49 AM
  5. Packaging and accessing data files
    By todd in forum Advanced Java
    Replies: 1
    Last Post: 08-01-2007, 12:27 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
  •