3 Replies Latest reply: Feb 17, 2010 8:26 AM by 800560 RSS

    Help on Creating Jar File

    843804
      I have a JavaBean called Symptoms stored in a package called voiceexpert. I have two other classes: Disease and DiagnosingEngine in the same package made use of by Symptoms. The package voiceexpert is stored inside the folder C:\Diagapp.

      My application which is a rule-based system makes use of an external jar file: jess.jar which has been added to the classpath. I wrote a main method to test the application and it is working perfectly. Now, my application is supposed to be called from a third party application through the JavaBean I created, in which case I do not need to have a main method. My third party application is going to call a method in the JavaBean.

      I want to create a jar file of the application without the main method; my third party application can only interact with the jar file of the application. What command will I use and in which directory am I going to issue the command? Do I need to also include the external jar file (jess.jar) used by the application inside the new jar file to be created for the application or what? My application also uses a file (diagnosing.CLP) which stores the application's rules. Do I also need to include this file as part of the jar file to be created?

      Note: I have created a jar file of the application according to what I have read but my third party application cannot see it. I suppose that I did not do it well.

      Thanks in advance for your anticipated responses.
        • 1. Re: Help on Creating Jar File
          800560
          Please note that I know almost nothing about Java Beans. I don't think that matters at this point.

          I think the first step is to jar up your app files and create a separate class with a main method to test your app when your app is in a jar. Your app jar must be in the classpath. If your app depends on jess.jar, then jess.jar needs to be in the classpath. (It is possible to extract the jess.jar classes and re-jar them, but that might violate the license for jess.jar.)

          I assume you have c:\Diagapp\voiceexpert\Symptoms.class along with the other voiceexpert classes. So if your current directory is C:\Diagapp, then

          jar cf voiceexpert.jar voiceexpert\*.class

          should be the command to jar the app.

          Does the .CLP file need to be modified or will it just be read? If it is read only, then you can put it in the jar file. Your code might need to be modified to find it in the jar file. You will have to treat it as a URL.

          After you can run your jar'ed app using your test method, you can try it with the 3rd party app. You just need to make sure all your jars and .class files are find-able via the classpath.
          • 2. Re: Help on Creating Jar File
            843804
            Thanks for your reply, but I am yet to understand some of your explanation.
            I understand that jess.jar must be in the classpath and I already did that before my post. But, are you saying that the jar file I create from my application will also be included in the classpath?
            Maybe I should first of all test the application with the main method first.
            The following is the way my files are arranged:

            C:\Diagapp\Expertapp.class
            C:\Diagapp\diagnosing.CLP

            C:\Diagapp\voiceexpert\Symptoms.class
            C:\Diagapp\voiceexpert\Disease.class
            C:\Diagapp\voiceexpert\DiagnosinEngine.class

            Note: Expert.class contains the main method.
            diagnosing.CLP is just to be read by the application
            Symptoms.class, Disease.class and DiagnosingEngine.class are all classes the application uses

            What step-by-step procedure should I follow to create a runnable jar file for the application and with what command will I test it?

            When jess.jar is included in the classpath before compiling the code, do I still need to extract its classes again in an attempt to create a jar file for the entire application?
            • 3. Re: Help on Creating Jar File
              800560
              Adeyi wrote:
              Thanks for your reply, but I am yet to understand some of your explanation.
              I understand that jess.jar must be in the classpath and I already did that before my post. But, are you saying that the jar file I create from my application will also be included in the classpath?
              Yes, the JVM looks for user classes by searching the classpath. (Unless you have written a custom classloader.)
              Maybe I should first of all test the application with the main method first.
              The following is the way my files are arranged:

              C:\Diagapp\Expertapp.class
              C:\Diagapp\diagnosing.CLP

              C:\Diagapp\voiceexpert\Symptoms.class
              C:\Diagapp\voiceexpert\Disease.class
              C:\Diagapp\voiceexpert\DiagnosinEngine.class

              Note: Expert.class contains the main method.
              diagnosing.CLP is just to be read by the application
              Symptoms.class, Disease.class and DiagnosingEngine.class are all classes the application uses
              Did you mean Expertapp.class? Or is there another class named Expert? I am assuming you mean Expertapp.
              What step-by-step procedure should I follow to create a runnable jar file for the application and with what command will I test it?
              I am assuming your current directory is C:\Diagapp and jess.jar is in that directory. I don't have time to create those directories and classes so the following is untested. It is likely that you need to modify your code to read Diagnosing.CLP if you want to put that in the jar.
              jar cf voiceexpert.jar voiceexpert\*.class Diagnosing.CLP
              java -cp jess.jar;voiceexpert.jar;. Expertapp 
              When jess.jar is included in the classpath before compiling the code, do I still need to extract its classes again in an attempt to create a jar file for the entire application?
              No, but both jars need to be in the classpath. You do not need to extract its classes at all.