10 Replies Latest reply on May 15, 2002 12:22 AM by arijit

    Creating JAR file

    arijit

      The online manual talks about an example called Interest file. They have said to use commands like "ant intro-interest-jar" to create the jar files. What happens if I develop my own EJB components? How do I create the jar file in that case?

        • 1. Re: Creating JAR file
          csanche7

          Just put your classes and META-INF directory (with ejb-jar.xml and jboss.xml) in a jar file whith the command:

          jar cvf <jar-name>.jar classes META-INF

          copy the jar file you have created to the deploy directory.

          That´s all.

          • 2. Re: Creating JAR file
            arijit

            Thanks...

            As I am a novice, please excuse me for these simple queries --

            1. Jar file created by ANT has META-INF directory and ORG directory. It does not have CLASSES directory.

            2. I have the Java files.. ANT helps in creating the CLASS files... Any other manual way to create the CLASS files?

            • 3. Re: Creating JAR file
              csanche7

              don´t worry

              Ok, you have your .java, now compile them whith javac, perhaps you have problems with classpath, use the -classpath option.

              javac -classpath <your-classpath-here> <your-classes>.java

              Now you have the compiled classes. Create the META-INF directory and the ejb-jar.xml, jboss.xml files. Pack your .class and the META-INF directory whith jar.

              jar cvf <jar-name>.jar <your classes>.class META-INF

              For example you have these directories:

              test/testEJB.class
              test/testHome.class
              test/testRemote.class
              test/META-INF/ejb-jar.xml
              test/META-INF/jboss.xml

              from test you should execute

              jar cvf test.jar *.class META-INF


              Charly

              • 4. Re: Creating JAR file
                arijit

                Thanks a lot Charly....

                I am trying to execute the Interest example (having 3 java files -- Interest.java, InterestBean.java, InterestHome.java) manually without the help of ANT (Is that advisable?)

                When I am compiling the first file i.e. Interest.java I am getting the following errors. Similar errors for other files too. However, I can easily compile any other ordinary JAVA files having main() function.

                Errors --

                C:\Jboss\JBoss-2.4.4\examples\org\jboss\docs\interest>javac Interest.java
                Interest.java:3: package javax.ejb does not exist
                import javax.ejb.EJBObject;
                ^
                Interest.java:11: cannot resolve symbol
                symbol : class EJBObject
                location: interface org.jboss.docs.interest.Interest
                public interface Interest extends EJBObject
                ^
                2 errors



                What am I doing wrong ?

                • 5. Re: Creating JAR file
                  csanche7

                  It´s a classpath problem. Just add the jboss-j2ee.jar file (it´s in jboss/lib/ext) to your classpath and everything should work fine.

                  Charly

                  • 6. Re: Creating JAR file
                    arijit

                    Thanks Charly... Yes its working now....

                    BUT :(

                    When I tried to compile InterestHome.java, it gave the following error --


                    C:\Jboss\JBoss-2.4.4\examples\org\jboss\docs\interest>javac InterestHome.java
                    InterestHome.java:17: cannot resolve symbol
                    symbol : class Interest
                    location: interface org.jboss.docs.interest.InterestHome
                    Interest create() throws RemoteException, CreateException;
                    ^
                    1 error



                    The file Interest.class exists in the same directory where I am compiling this InterestHome.java file


                    Please advise

                    • 7. Re: Creating JAR file
                      csanche7

                      It could be another classpath problem. Try compiling this way:

                      javac -classpath . InterestHome.java

                      with this you add the directory where you are to your classpath.

                      Charly

                      • 8. Re: Creating JAR file
                        arijit

                        Didn't work Charly...

                        When I added the current directory in my classpath and gave the command "javac -classpath . InterestHome.java"

                        it showed 5 errors ----

                        InterestHome.java:5: package javax.ejb does not exist
                        import javax.ejb.CreateException;
                        ^
                        InterestHome.java:6: package javax.ejb does not exist
                        import javax.ejb.EJBHome;
                        ^
                        InterestHome.java:11: cannot resolve symbol
                        symbol : class EJBHome
                        location: interface org.jboss.docs.interest.InterestHome
                        public interface InterestHome extends EJBHome
                        ^
                        InterestHome.java:17: cannot resolve symbol
                        symbol : class Interest
                        location: interface org.jboss.docs.interest.InterestHome
                        Interest create() throws RemoteException, CreateException;
                        ^
                        InterestHome.java:17: cannot resolve symbol
                        symbol : class CreateException
                        location: interface org.jboss.docs.interest.InterestHome
                        Interest create() throws RemoteException, CreateException;
                        ^
                        5 errors


                        If I however I gave the command, "javac InterestHome.java
                        " I am still receiving that 1 error ---

                        InterestHome.java:17: cannot resolve symbol
                        symbol : class Interest
                        location: interface org.jboss.docs.interest.InterestHome
                        Interest create() throws RemoteException, CreateException;
                        ^
                        1 error



                        Can you help me ?

                        • 9. Re: Creating JAR file
                          csanche7

                          It seems you have the jboss-j2ee.jar in your system classpath. Try adding the "." to it.

                          set classpath=%classpath%;. (Windows)

                          and then compile.

                          Charly

                          • 10. Re: Creating JAR file
                            arijit

                            Hi Charly,

                            Thanks for your help. I commented the package statement in each of the 3 Interest files and then compiled. It compiled. All the 3 class files have now been generated.

                            The 3 class files and the META-INF directory are in the following directory -- "C:\Jboss\JBoss-2.4.4\examples\org\jboss\docs\interest"

                            I am presently in this directory itself and trying to execute ---
                            "jar cvf interest.jar *.class META-INF"

                            This helps in creating the jar file properly.

                            Now when I am trying to deploy this file, it is showing errors probably because the class files are supposed to be in a directory hierarchy like --- "org.jboss.docs.interest"

                            So I placed the class files in that directory hierarchy and executed the following command --
                            "jar cvf interest.jar org META-INF"

                            The jar file, thus created, should have been correct.

                            But even when I placed the class files in a directory hierarchy "org.jboss.docs.interest", deployment still gave errors.

                            This is probably because I compiled the java files after commenting out the package statements which had this path "org.jboss.docs.interest". So the class files created were not correct.

                            If I try to compile the java files with the package statement, then I am getting yesterday's errors.



                            So do I need to change some XML file to to make it work ? or the configuration file maybe ? Or maybe compile it from the top of the hierarchy level "org.jboss.docs.interest" ? Can you please help ?