5 Replies Latest reply on Sep 25, 2007 7:37 AM by 807600

    Serial port icaste runs but not jar file

      I hope this is not a duplicate post, I thought I posted it last night but I don't see it on the forum.

      I got my serial port code to compile and run in the Eclipse environment.

      Picture of screen.

      I made a jar file using the Eclipse Export of a simple HelloWorld and it runs from the command line using

      java -jar HelloWorld.jar

      The TestSerial.jar file is giving me an error.

      Exception in thread "main" java.lang.NoClassDefFoundError: com/icaste/JCommSerial/SerialPortNotFoundException

      When I comment out the code for that catch block (not sure if catch block is correct term) it then gives an error on the next catch block catch(SerialPortInUseException e)

      When I remove all the catch blocks except for the catch(Throwable e) When running from command line I get:

      Exception in thread "main" java.lang.NoClassDefFoundError: com/icaste/JCommSerial/SerialPort at TrySerial.main(TrySerial.java:19)

      I see that it refers to line 19 SerialPort myport = new SerialPort();

      Question: What am I missing in the code? Instances of the classes?

      Question: What is the lower case e in the catch block?

      Question: I don't see an attach button to attach code or pictures in this forum. Should I put a java src file on my server to list the code? Is there a code block I can use to keep formatting for the readablity of the code on the forum?
        • 1. Re: Serial port icaste runs but not jar file
          {color:#000080}Hello metron9

          Let's deal with the easy ones to begin with (the tough ones are beyond me ;-)

          java.lang.NoClassDefFoundError means that a needed class could not be found. From your own research, you know that was the class SerialPort. Check whether you have imported the package containing SerialPort (I take it that's not one of your own classes).

          The lowercase e is just the variable name for the Exception being caught... the catch block takes a parameter. Just like in method signatures, the class of the parameter is folowed by a variable name. You could just as well have
          catch ( Exception metron9 ) {
          and it would still work the same... the variable is scoped to the catch block, and is not available outside of that.

          To post code, use code tags --{color} [code]CODE[/code] {color:#000080}is displayed as
          No provision for posting pictures, though.

          And your earlier post is at

          You might like to post a response on that thread with a link to this one.

          All the best, Darryl{color}
          • 2. Re: Serial port icaste runs but not jar file
            Thanks Darryl that makes some sense. If I understand it correctly the e or whatever symbol you provide is automatically defined as a variable of the correct type and used in the catch method as a parameter to the Exception method. Not sure why the catch method cant just define its own internal variable before calling the Exception method though.

            Indeed on the other question, it seems the jar file I made does not contain or have access to the SerialPort class within the serial port jar file. I will try and fix that tonight. You would think the Export function that makes a stand alone jar file designed to be distributed would have enough sense to know this at the time you make the jar file or have a button that you can check to include all necessary files for a stand alone java program. The only time I have had these problems in the past with compilers from Masm to Clipper/blinker is having the compiler complain it could not find a file. Once it made an exe file though all the code necessary was in there. I suppose it is the culture today of updating programs on a weekly basis. I wrote programs 15 years ago that my company uses every day and I have never had to do an update. Of course that's because I forgot how to recompile them, I Sure wish I had used a timer instead of a for next loop in them though, back when we had 4Mhz IBM machines those delays were a few seconds. Now they are milliseconds. So yes, I really do need to update them, but how many updates do I need of itunes?
            • 3. Re: Serial port icaste runs but not jar file
              it seems the jar file I made does not contain or have access to the SerialPort class within the serial port jar file.
              {color:#000080}Hmm... I don't use Eclipse but I fired it up and took a looksee -- I think (note: think, not know) this might do the trick.

              Right click somewhere in your project tree and select Build Path --> Configure Build Path. In the dialog, click Add External Jars. Etc.

              The added jar appears under Refrenced Libraries in the Project tree.

              If nobody else responds, you could try that while you're waiting :-)


              the Exception method
              {color:#000080}Exception is a class, the superclass of all exceptions.

              Edited by: Darryl.Burke
              • 4. Re: Serial port icaste runs but not jar file
                I will try that, thanks. I have to have a drink first for my colorsteral. I also found this thread that says you can't put a jar in a jar. http://www.eclipsezone.com/eclipse/forums/t101559.html

                Ok It is solved. I used the Eclipse plugin http://fjep.sourceforge.net/

                Worked the first time I tried it

                I found the information for fat jar plugin at this site http://www.eclipsezone.com/eclipse/forums/t101559.html

                Now on with the coding... but first i better have that drink, we had a storm blow through here and I am a little wired as well as it seems every time I get a problem solved I take a long break and just mull it over for a while. I am not in any hurry to get something done, I just like to get something done each day. Baby steps.

                Thanks to all for input, i hope this can help others as well using Eclipse.

                Edited by: metron9 on Sep 24, 2007 4:31 PM
                • 5. Re: Serial port icaste runs but not jar file
                  Ok I have spent the last 5 hours trying to get netbeans to run an external jar file. I finally found this that solved the problem.


                  I had everything right. the only thing i did wrong was to not have a folder named lib with the external jar file in it. The window was closed in my netbeans for the Files View, once I found that and looked at the MANIFEST.MF file it read

                  Manifest-Version: 1.0
                  Ant-Version: Apache Ant 1.6.5
                  Created-By: 1.6.0_02-b06 (Sun Microsystems Inc.)
                  Main-Class: newtest
                  Class-Path: lib/JCommSerial_3_0.jar
                  X-COMMENT: Main-Class will be added automatically by build

                  And there it is Class-path:lib/JCommSerial_3_0.jar

                  Now the only real dumb thing is this. In all my years of compiling programs with other languages, when I would try and open a file I needed on any system and was unable to open it, i would give an error message that would go something like this.

                  Error: Unable to open library file \lib\JCommSerial_3_0.jar

                  not something like this:

                  Exception in thread "main" java.lang.NoClassDefFoundError: com/icast/JCommSerial/SerialPortNotFoundException

                  For all the magic that is done in java, and I mean that so far i can see this stuff is very powerful. But i find the error messages a bit confusing. Even after reading the document that details the error message, you might think somewhere they could put a hint that the jar file was not found AND where it was trying to find the darn thing.

                  Ok that's three major problems in two days solved. Now perhaps I can actually do some programming in java.