11 Replies Latest reply: May 5, 2010 4:24 PM by 801571 RSS

    problem accessing class in jar file

    801571
      Hello. I am trying to create a jar file from my already compiled classes. I have around 5 packages, and my programs' entry point is in one of the packages, we'll call package A. Each package has its own purpose and package A calls any needed package to perform their task. This works well when I compile, run and all. However, when I create a jar file, it only works with the local package and any calls to another package do not work. How can I get around this? any help will be appreciated
        • 1. Re: problem accessing class in jar file
          793415
          joshmo wrote:
          ..any calls to another package do not work. ..
          - Maybe the calls are just 'all tuckered out'. Give them a warm cup of cocoa and a good night's sleep and try them in the morning.
          - Maybe the calls are just lazy. Try the carrot and/or stick approach.
          - Maybe the calls are having some other problem, in which case, I'd suggest you refrain from paraphrasing the error, and instead [copy/paste the exception or error message|http://pscode.org/javafaq.html#exact] that is being produced.
          • 2. Re: problem accessing class in jar file
            801571
            well thats the thing..I do not get any error message..It just does not respond. I created the JAR file using eclipse..here is the generated ant file
            <?xml version="1.0" encoding="UTF-8" standalone="no"?>
            <project default="create_run_jar" name="Create Runnable Jar for Project HMS">
                <!--this file was created by Eclipse Runnable JAR Export Wizard-->
                <!--ANT 1.7 is required                                        -->
                <target name="create_run_jar">
                    <jar destfile="C:/Users/User/Desktop/MYJAR.jar" filesetmanifest="mergewithoutmain">
                        <manifest>
                            <attribute name="Main-Class" value="Login.loginMain"/>
                            <attribute name="Class-Path" value="."/>
                        </manifest>
                        <fileset dir="C:/Users/User/Documents/Project/Implementation"/>
                    </jar>
                </target>
            </project>
            • 3. Re: problem accessing class in jar file
              793415
              joshmo wrote:
              ..I do not get any error message..
              What (if any) output do you get from..
              prompt> java -jar C:/Users/User/Desktop/MYJAR.jar
              • 4. Re: problem accessing class in jar file
                801571
                no error message or any message output. My UI in the main package opens and I cant call any other UI in another package
                • 5. Re: problem accessing class in jar file
                  793415
                  joshmo wrote:
                  no error message or any message output.
                  OK. Note that the first letter of every sentence should be upper case.

                  Is the code [swallowing exceptions|http://pscode.org/javafaq.html#stacktrace] at any point?
                  ..My UI in the main package opens and I cant call any other UI in another package
                  How do you know that if there is absolutely no error output?
                  ---------------
                  What is the output for these two commands (untested - adjust to need)?
                  prompt> dir C:/Users/User/Desktop/*.jar
                  prompt> dir C:/Users/User/Documents/Project/Implementation/*.jar
                  What is the final content of the manifest file?
                  • 6. Re: problem accessing class in jar file
                    801571
                    This is the output..
                    05/05/2010  10:19 AM        10,946,787 MYJAR.jar
                                   1 File(s)     10,946,787 bytes
                                   0 Dir(s)   1,434,251,264 bytes free
                    My manifest file contains
                    Manifest-Version: 1.0
                    Class-Path: .
                    Main-Class: Login.loginMain
                    AndrewThompson64 wrote:Is the code [swallowing exceptions|http://pscode.org/javafaq.html#stacktrace] at any point?
                    Nope..
                    AndrewThompson64 wrote:
                    How do you know that if there is absolutely no error output?
                    The when I ran the code from my compiler, it has no errors, and it works smoothly. I have used a JAR for a single package program before and it worked well but this multiple package program is giving me the problem and I don't want to put all the files in a single package
                    • 7. Re: problem accessing class in jar file
                      EJP
                      I believe the class-path of a manifest file can only name other .jar files.
                      • 8. Re: problem accessing class in jar file
                        793415
                        ejp wrote:
                        I believe the class-path of a manifest file can only name other .jar files.
                        <head-desk /> The ['Understanding class path wildcards' section of 'Setting the class path'|http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html] supports your statement.
                        ..class path wildcards are not honored in the Class-Path jar-manifest header.
                        I was thinking of the abilities of the SDK tools to accept wildcards. I am still curious as to why that produced no exceptions or errors in the output.
                        • 9. Re: problem accessing class in jar file
                          801571
                          Pardon my misrepresentation. Perharps when I was running the jar file I didn't maneuver around the program fully. I happened to get an exception which is "no suitable driver found" I have been checking this out almost all day and have failed to get a work around. On some forums I read adding "Class.forName("com.mysql.jdbc.Driver")" would help, but it throws a "class not found exception". My class paths are all okay because I can access the database from the actual program. I have tried adding the "mysql-connector-java-5.1.10-bin.jar" to the Manifest file but this does not do the trick so I am kind of confused on what to do, or perhaps I have got myself jumbled up.
                          • 10. Re: problem accessing class in jar file
                            793415
                            joshmo wrote:
                            ..I have tried adding the "mysql-connector-java-5.1.10-bin.jar" to the Manifest file but this does not do the trick so I am kind of confused on what to do, or perhaps I have got myself jumbled up.
                            Sure. But my understanding of the manifest class-path is that to be found, the Jar specified with no path would need to be in the same directory as your main Jar. Your directory listing in reply 6 suggests it is not in that directory.
                            • 11. Re: problem accessing class in jar file
                              801571
                              That has actually done the trick for me. Thanks alot