So you’ve built your Java Application against our Common Library. You load it on the JNIOR. You try to execute it and… It throws Class Not Found Exceptions!

This is because your application references the code in the Common Library but Janos cant find it. The only external JAR file to your application that JANOS can handle it the JanosClasses.jar file in the etc/ directory. That JAR file is bundled with the operating system.

So how do we handle this? We stuff all of the needed classes from the Common Library into your applications JAR file. Sure, you could take ALL of the classes but that would just waste space and slow do the program because it would be slightly slower to unpack the needed classes during execution.

To do this we can use the Java Dependencies windows application supplied with the Embedded JANOS SDK. We can inject some code into our build.xml file to pull all of the NEEDED classes out of the Common Library and place them in our applications build directory. This way they will be available when NetBeans goes to package the JAR file. That code looks like this…

<target name="-pre-jar">
     <!-- before we build the JAR file we need to get all of the classes out of the
      library that our application depends on -->
     <echo>Update classes directory with library dependencies</echo>
     <exec dir="" resolveexecutable="true" executable="${janossdk.javadependencies}">
         <arg line="${build.classes.dir} '${libs.INTEG.Common.classpath}'"/>
     </exec>
</target>

Now when our application is built the compilation output will show the Java class dependency discovery and what classes are copied into your application. Here is an example from a test applicaiton that will perform some logging and monitor some I/O. The application will perform 4 steps.

  1. First it will list all of the classes in the Common Library.
  2. Then it will parse the byte codes in the .class files to find external class references. If the class depends on an external class then it is listed. If it is the first time the application saw that dependency then an * is appended.
  3. Next each class that was depended on will be displayed along with a list of the classes that depended on it.
  4. Lastly, a list of each class that is copied along with its file size is displayed.
Update classes directory with library dependencies
 Version 2.1
 Project directory: C:\Users\kcloutier\Documents\Sandbox\Embedded Applications\Playground\CommonTest\build\classes
 Library directory: C:\Users\kcloutier\Documents\Sandbox\Embedded Applications\INTEG Applications_Common\dist_Common.jar
 --- Unpack Library: C:\Users\kcloutier\Documents\Sandbox\Embedded Applications\INTEG Applications_Common\dist_Common.jar to C:\INTEG\JANOS_SDK\temp
 1 com/integ/common/CommonLib.class
 2 com/integ/common/collections/BlockingQueue.class
 3 com/integ/common/collections/CircularQueue.class
 4 com/integ/common/datastructures/CircularQueue.class
 5 com/integ/common/datastructures/ComparableLinkedListNode.class
 6 com/integ/common/datastructures/LinkedList.class
 7 com/integ/common/datastructures/LinkedListNode.class
 8 com/integ/common/datastructures/Queue.class
 9 com/integ/common/iolog/DigitalInputChannelEvent.class
 10 com/integ/common/iolog/DigitalInputsEvent.class
 11 com/integ/common/iolog/DigitalInputsIoLogMonitor.class
 12 com/integ/common/iolog/IoChannelEvent.class
 13 com/integ/common/iolog/IoChannelLogListener.class
 14 com/integ/common/iolog/IoLogListener.class
 15 com/integ/common/iolog/IoLogMonitor.class
 16 com/integ/common/iolog/RelayOutputChannelEvent.class
 17 com/integ/common/iolog/RelayOutputsEvent.class
 18 com/integ/common/iolog/RelayOutputsIoLogMonitor.class
 19 com/integ/common/logging/AppLog.class
 20 com/integ/common/logging/BakFileLog.class
 21 com/integ/common/logging/BakLogOutputStream.class
 22 com/integ/common/logging/BufferedLineOutputStream.class
 23 com/integ/common/logging/FileLog.class
 24 com/integ/common/logging/FileLogService.class
 25 com/integ/common/logging/LogOutputStream.class
 26 com/integ/common/logging/Logger.class
 27 com/integ/common/logging/NullOutLog.class
 28 com/integ/common/logging/RollingFileLog.class
 29 com/integ/common/logging/RollingLogOutputStream.class
 30 com/integ/common/logging/SystemOutLog.class
 31 com/integ/common/messagepump/ApplicationSystemMsg.class
 32 com/integ/common/messagepump/MessagePumpAppHandler.class
 33 com/integ/common/messagepump/MessagePumpAppMessageListener.class
 34 com/integ/common/messagepump/MessagePumpEngine$1.class
 35 com/integ/common/messagepump/MessagePumpEngine$2.class
 36 com/integ/common/messagepump/MessagePumpEngine.class
 37 com/integ/common/messagepump/MessagePumpListener.class
 38 com/integ/common/messagepump/SystemMsgTypes.class
 39 com/integ/common/net/AsciiCommandClient.class
 40 com/integ/common/net/BytesReceivedEvent.class
 41 com/integ/common/net/ClientListener.class
 42 com/integ/common/net/IClient.class
 43 com/integ/common/net/MessageReceivedEvent.class
 44 com/integ/common/net/NullClient.class
 45 com/integ/common/net/TCPConnectionListenerNotifier.class
 46 com/integ/common/net/TcpConnection$1.class
 47 com/integ/common/net/TcpConnection.class
 48 com/integ/common/net/TcpConnectionListener.class
 49 com/integ/common/net/TcpServer.class
 50 com/integ/common/net/TcpServerEvent.class
 51 com/integ/common/net/TcpServerListener.class
 52 com/integ/common/net/UdpConnectionListener.class
 53 com/integ/common/net/UdpServer.class
 54 com/integ/common/net/http/HttpRequest.class
 55 com/integ/common/net/http/HttpResponse.class
 56 com/integ/common/net/http/HttpURL.class
 57 com/integ/common/net/protocols/MessageListener.class
 58 com/integ/common/net/protocols/modbus/ModbusCollection.class
 59 com/integ/common/net/protocols/modbus/connections/ModbusConnection.class
 60 com/integ/common/net/protocols/modbus/connections/SerialModbusConnection.class
 61 com/integ/common/net/protocols/modbus/connections/TcpModbusConnection.class
 62 com/integ/common/net/protocols/modbus/functions/LoginRequest.class
 63 com/integ/common/net/protocols/modbus/functions/LoginResponse.class
 64 com/integ/common/net/protocols/modbus/functions/ModbusFunctionRequest.class
 65 com/integ/common/net/protocols/modbus/functions/ModbusFunctionResponse.class
 66 com/integ/common/net/protocols/modbus/functions/ModbusPdu.class
 67 com/integ/common/net/protocols/modbus/functions/ReadCoils.class
 68 com/integ/common/net/protocols/modbus/functions/ReadDiscreteInputs.class
 69 com/integ/common/net/protocols/modbus/functions/ReadHoldingRegisters.class
 70 com/integ/common/net/protocols/modbus/functions/ReadHoldingRegistersRequest.class
 71 com/integ/common/net/protocols/modbus/functions/ReadHoldingRegistersResponse.class
 72 com/integ/common/net/protocols/modbus/functions/ReadInputRegisters.class
 73 com/integ/common/net/protocols/modbus/functions/ReportSlaveId.class
 74 com/integ/common/net/protocols/modbus/functions/WriteMultipleCoils.class
 75 com/integ/common/net/protocols/modbus/functions/WriteMultipleRegisters.class
 76 com/integ/common/net/protocols/modbus/functions/WriteSingleCoil.class
 77 com/integ/common/net/protocols/modbus/functions/WriteSingleRegister.class
 78 com/integ/common/net/protocols/modbus/protocols/ModbusAsciiProtocol.class
 79 com/integ/common/net/protocols/modbus/protocols/ModbusProtocol.class
 80 com/integ/common/net/protocols/modbus/protocols/ModbusRTUProtocol.class
 81 com/integ/common/net/protocols/modbus/protocols/ModbusTCPProtocol.class
 82 com/integ/common/system/Application.class
 83 com/integ/common/system/ApplicationWatchdog.class
 84 com/integ/common/system/AssemblyBase.class
 85 com/integ/common/system/JniorApplication.class
 86 com/integ/common/system/ReleaseInfo.class
 87 com/integ/common/system/UnitConfig.class
 88 com/integ/common/utils/DateUtils.class
 89 com/integ/common/utils/ExceptionUtils.class
 90 com/integ/common/utils/FileUtils.class
 91 com/integ/common/utils/HexUtils.class
 92 com/integ/common/utils/JsonUtils.class
 93 com/integ/common/utils/ObjectUtils.class
 94 com/integ/common/utils/RegistryUtils.class
 95 com/integ/common/utils/StringUtils.class
 96 java/text/QuickDateFormat.class
 Parsing commontest/AssemblyInfo ---
   commontest/AssemblyInfo requires the following classes ---
     Depends on: com/integ/common/system/AssemblyBase *
 Parsing commontest/CommonTest ---
   commontest/CommonTest requires the following classes ---
     Depends on: com/integ/common/system/JniorApplication *
 Parsing commontest/IoLogTest$1 ---
   commontest/IoLogTest$1 requires the following classes ---
     Depends on: com/integ/common/iolog/IoLogListener *
     Depends on: java/text/QuickDateFormat *
 Parsing commontest/IoLogTest ---
   commontest/IoLogTest requires the following classes ---
     Depends on: com/integ/common/iolog/DigitalInputsIoLogMonitor *
     Depends on: java/text/QuickDateFormat
 Parsing commontest/LogTest ---
   commontest/LogTest requires the following classes ---
     Depends on: com/integ/common/logging/Logger *
     Depends on: com/integ/common/logging/RollingFileLog *
     Depends on: com/integ/common/logging/BakFileLog *
     Depends on: com/integ/common/logging/SystemOutLog *
     Depends on: com/integ/common/logging/NullOutLog *
 Parsing com/integ/common/system/AssemblyBase ---
 Parsing com/integ/common/system/JniorApplication ---
 Parsing com/integ/common/iolog/IoLogListener ---
 Parsing java/text/QuickDateFormat ---
 Parsing com/integ/common/iolog/DigitalInputsIoLogMonitor ---
   com/integ/common/iolog/DigitalInputsIoLogMonitor requires the following classes ---
     Depends on: com/integ/common/iolog/DigitalInputChannelEvent *
     Depends on: com/integ/common/iolog/IoChannelLogListener *
     Depends on: com/integ/common/iolog/IoLogMonitor *
     Depends on: com/integ/common/system/UnitConfig *
     Depends on: java/text/QuickDateFormat
 Parsing com/integ/common/logging/Logger ---
 Parsing com/integ/common/logging/RollingFileLog ---
   com/integ/common/logging/RollingFileLog requires the following classes ---
     Depends on: com/integ/common/logging/Logger
     Depends on: com/integ/common/logging/RollingLogOutputStream *
     Depends on: com/integ/common/logging/FileLog *
     Depends on: com/integ/common/logging/FileLogService *
     Depends on: com/integ/common/logging/SystemOutLog
 Parsing com/integ/common/logging/BakFileLog ---
   com/integ/common/logging/BakFileLog requires the following classes ---
     Depends on: com/integ/common/logging/Logger
     Depends on: com/integ/common/logging/BakLogOutputStream *
     Depends on: com/integ/common/logging/FileLog
     Depends on: com/integ/common/logging/FileLogService
     Depends on: com/integ/common/logging/SystemOutLog
 Parsing com/integ/common/logging/SystemOutLog ---
   com/integ/common/logging/SystemOutLog requires the following classes ---
     Depends on: com/integ/common/logging/Logger
 Parsing com/integ/common/logging/NullOutLog ---
   com/integ/common/logging/NullOutLog requires the following classes ---
     Depends on: com/integ/common/logging/Logger
 Parsing com/integ/common/iolog/DigitalInputChannelEvent ---
   com/integ/common/iolog/DigitalInputChannelEvent requires the following classes ---
     Depends on: com/integ/common/iolog/IoChannelEvent *
 Parsing com/integ/common/iolog/IoChannelLogListener ---
 Parsing com/integ/common/iolog/IoLogMonitor ---
   com/integ/common/iolog/IoLogMonitor requires the following classes ---
     Depends on: com/integ/common/iolog/DigitalInputsIoLogMonitor
     Depends on: com/integ/common/iolog/RelayOutputsIoLogMonitor *
     Depends on: com/integ/common/iolog/IoLogListener
     Depends on: java/text/QuickDateFormat
     Depends on: com/integ/common/iolog/IoChannelLogListener
     Depends on: com/integ/common/logging/SystemOutLog
     Depends on: com/integ/common/logging/Logger
 Parsing com/integ/common/system/UnitConfig ---
 Parsing com/integ/common/logging/RollingLogOutputStream ---
   com/integ/common/logging/RollingLogOutputStream requires the following classes ---
     Depends on: com/integ/common/logging/LogOutputStream *
 Parsing com/integ/common/logging/FileLog ---
   com/integ/common/logging/FileLog requires the following classes ---
     Depends on: java/text/QuickDateFormat
     Depends on: com/integ/common/logging/BufferedLineOutputStream *
     Depends on: com/integ/common/logging/Logger
     Depends on: com/integ/common/logging/LogOutputStream
     Depends on: com/integ/common/logging/FileLogService
 Parsing com/integ/common/logging/FileLogService ---
   com/integ/common/logging/FileLogService requires the following classes ---
     Depends on: com/integ/common/logging/Logger
 Parsing com/integ/common/logging/BakLogOutputStream ---
   com/integ/common/logging/BakLogOutputStream requires the following classes ---
     Depends on: com/integ/common/logging/LogOutputStream
     Depends on: com/integ/common/utils/FileUtils *
 Parsing com/integ/common/iolog/IoChannelEvent ---
 Parsing com/integ/common/iolog/RelayOutputsIoLogMonitor ---
   com/integ/common/iolog/RelayOutputsIoLogMonitor requires the following classes ---
     Depends on: com/integ/common/iolog/RelayOutputChannelEvent *
     Depends on: com/integ/common/iolog/IoChannelLogListener
     Depends on: com/integ/common/iolog/IoLogMonitor
     Depends on: com/integ/common/system/UnitConfig
     Depends on: java/text/QuickDateFormat
 Parsing com/integ/common/logging/LogOutputStream ---
   com/integ/common/logging/LogOutputStream requires the following classes ---
     Depends on: com/integ/common/utils/FileUtils
 Parsing com/integ/common/logging/BufferedLineOutputStream ---
 Parsing com/integ/common/utils/FileUtils ---
 Parsing com/integ/common/iolog/RelayOutputChannelEvent ---
   com/integ/common/iolog/RelayOutputChannelEvent requires the following classes ---
     Depends on: com/integ/common/iolog/IoChannelEvent
 com/integ/common/iolog/DigitalInputChannelEvent
    is referenced by com/integ/common/iolog/DigitalInputsIoLogMonitor
 com/integ/common/iolog/DigitalInputsIoLogMonitor
    is referenced by commontest/IoLogTest
    is referenced by com/integ/common/iolog/IoLogMonitor
 com/integ/common/iolog/IoChannelEvent
    is referenced by com/integ/common/iolog/DigitalInputChannelEvent
    is referenced by com/integ/common/iolog/RelayOutputChannelEvent
 com/integ/common/iolog/IoChannelLogListener
    is referenced by com/integ/common/iolog/DigitalInputsIoLogMonitor
    is referenced by com/integ/common/iolog/IoLogMonitor
    is referenced by com/integ/common/iolog/RelayOutputsIoLogMonitor
 com/integ/common/iolog/IoLogListener
    is referenced by commontest/IoLogTest$1
    is referenced by com/integ/common/iolog/IoLogMonitor
 com/integ/common/iolog/IoLogMonitor
    is referenced by com/integ/common/iolog/DigitalInputsIoLogMonitor
    is referenced by com/integ/common/iolog/RelayOutputsIoLogMonitor
 com/integ/common/iolog/RelayOutputChannelEvent
    is referenced by com/integ/common/iolog/RelayOutputsIoLogMonitor
 com/integ/common/iolog/RelayOutputsIoLogMonitor
    is referenced by com/integ/common/iolog/IoLogMonitor
 com/integ/common/logging/BakFileLog
    is referenced by commontest/LogTest
 com/integ/common/logging/BakLogOutputStream
    is referenced by com/integ/common/logging/BakFileLog
 com/integ/common/logging/BufferedLineOutputStream
    is referenced by com/integ/common/logging/FileLog
 com/integ/common/logging/FileLog
    is referenced by com/integ/common/logging/RollingFileLog
    is referenced by com/integ/common/logging/BakFileLog
 com/integ/common/logging/FileLogService
    is referenced by com/integ/common/logging/RollingFileLog
    is referenced by com/integ/common/logging/BakFileLog
    is referenced by com/integ/common/logging/FileLog
 com/integ/common/logging/Logger
    is referenced by commontest/LogTest
    is referenced by com/integ/common/logging/RollingFileLog
    is referenced by com/integ/common/logging/BakFileLog
    is referenced by com/integ/common/logging/SystemOutLog
    is referenced by com/integ/common/logging/NullOutLog
    is referenced by com/integ/common/iolog/IoLogMonitor
    is referenced by com/integ/common/logging/FileLog
    is referenced by com/integ/common/logging/FileLogService
 com/integ/common/logging/LogOutputStream
    is referenced by com/integ/common/logging/RollingLogOutputStream
    is referenced by com/integ/common/logging/FileLog
    is referenced by com/integ/common/logging/BakLogOutputStream
 com/integ/common/logging/NullOutLog
    is referenced by commontest/LogTest
 com/integ/common/logging/RollingFileLog
    is referenced by commontest/LogTest
 com/integ/common/logging/RollingLogOutputStream
    is referenced by com/integ/common/logging/RollingFileLog
 com/integ/common/logging/SystemOutLog
    is referenced by commontest/LogTest
    is referenced by com/integ/common/logging/RollingFileLog
    is referenced by com/integ/common/logging/BakFileLog
    is referenced by com/integ/common/iolog/IoLogMonitor
 com/integ/common/system/AssemblyBase
    is referenced by commontest/AssemblyInfo
 com/integ/common/system/JniorApplication
    is referenced by commontest/CommonTest
 com/integ/common/system/UnitConfig
    is referenced by com/integ/common/iolog/DigitalInputsIoLogMonitor
    is referenced by com/integ/common/iolog/RelayOutputsIoLogMonitor
 com/integ/common/utils/FileUtils
    is referenced by com/integ/common/logging/BakLogOutputStream
    is referenced by com/integ/common/logging/LogOutputStream
 java/text/QuickDateFormat
    is referenced by commontest/IoLogTest$1
    is referenced by commontest/IoLogTest
    is referenced by com/integ/common/iolog/DigitalInputsIoLogMonitor
    is referenced by com/integ/common/iolog/IoLogMonitor
    is referenced by com/integ/common/logging/FileLog
    is referenced by com/integ/common/iolog/RelayOutputsIoLogMonitor
 Copy com\integ\common\iolog\DigitalInputChannelEvent.class (0.50KB)
 Copy com\integ\common\iolog\DigitalInputsIoLogMonitor.class (2.73KB)
 Copy com\integ\common\iolog\IoChannelEvent.class (0.46KB)
 Copy com\integ\common\iolog\IoChannelLogListener.class (0.21KB)
 Copy com\integ\common\iolog\IoLogListener.class (0.21KB)
 Copy com\integ\common\iolog\IoLogMonitor.class (6.01KB)
 Copy com\integ\common\iolog\RelayOutputChannelEvent.class (0.47KB)
 Copy com\integ\common\iolog\RelayOutputsIoLogMonitor.class (2.69KB)
 Copy com\integ\common\logging\BakFileLog.class (1.95KB)
 Copy com\integ\common\logging\BakLogOutputStream.class (1.74KB)
 Copy com\integ\common\logging\BufferedLineOutputStream.class (1.09KB)
 Copy com\integ\common\logging\FileLog.class (2.66KB)
 Copy com\integ\common\logging\FileLogService.class (2.13KB)
 Copy com\integ\common\logging\Logger.class (2.49KB)
 Copy com\integ\common\logging\LogOutputStream.class (1.87KB)
 Copy com\integ\common\logging\NullOutLog.class (0.68KB)
 Copy com\integ\common\logging\RollingFileLog.class (1.97KB)
 Copy com\integ\common\logging\RollingLogOutputStream.class (3.20KB)
 Copy com\integ\common\logging\SystemOutLog.class (0.70KB)
 Copy com\integ\common\system\AssemblyBase.class (1.56KB)
 Copy com\integ\common\system\JniorApplication.class (0.49KB)
 Copy com\integ\common\system\UnitConfig.class (1.60KB)
 Copy com\integ\common\utils\FileUtils.class (4.33KB)
 Copy java\text\QuickDateFormat.class (5.75KB)
 Copied 24 files totalling 47.50KB
 3.07 seconds