How to add a jar file to application to use in runtime?

Most of the time people face Java.Lang.NoClassDefFoundError error in runtime because their application is dependent on .jar file that is missing in runtime. In IIB, .jar files can be made available to applications at runtime in multiple ways.

2 answers

By default, IIB will load any .jar file you add at the following locations:

/var/mqsi/shared-classes : Any jar file you place here will be accessible to all Nodes on your system.

/var/mqsi/config/IIBNODE/hared-classes : any jar file you place here will ONLY be accessible by the all EGs under this node only. A quick note: sometimes, you may not see this the shared-classes directory right under the node directory. In that case you must create it manually and it stays there until you manually delete it if no longer need

/var/mqsi/config/IIBNODE/EG/shared-classes : any jar file you place here will ONLY be accessible by all applications deployed to this EG only. A quick note: sometimes, you may not see this the shared-classes directory right under the EG directory. In that case you must create it manually and it stays there until you manually delete it if no longer need
The .jar file you place in any of those directories will be loaded by the broker internal classloader on start up.
PS. If you started the broker before adding any .jar file at any of those locations, just know that the .jar file will not be available for use at runtime. To correct this you need to CYCLE the broker.

B- Adding jar file to broker archive

You can also add a jar file to a broker archive directly following these steps.
Use 7zip or any archive file editor to open the BAR file. Inside you will see one “META-INF” and one or more .zip files each containing your applications. Please, note that if your bar file has .bar extension, you can simply rename it to .zip without making any change to the file name itself. Otherwise your application will not work
If you place the .jar file at the same level as the “META-INF” directory, all application deployed on the EG will have access to the jar file.
However, if you open any of your application file with .zip extension and place at the same level as all other files/directory in the application zip file, only that application will have access to the .jar file.
PS. Just remember to rename the main bar file with .bar extension you changed earlier to keep things consistent.

C- Adding jar file to broker archive via toolkit

It is also possible to add .jar file to a BAR file directly in the toolkit. To do so, first drag and drop your jar file from anywhere on your computer into the IIB toolkit workspace. You can drag and drop it on Independent Resources directory or onto the application directory (IIB will automatically move this jar file to Other Resources directory, but that is fine).
Now open the BAR file you want to add the jar file to. Make sure the Prepare tab is selected and Message flows, static libraries and other message flow dependencies is also selected.
You should see a list of your application or/and lib and other resources including the jar file.
Make your application as well as the jar file, which is usually at the end of the list, are checked. You may need to scroll to the end of the list. After you finish with your selection, click Build and Save.
If the build and save is successful, then your jar file is also packaged with your application and will be made available to the application in runtime.

A- Adding jar file to shared-classes directories
By default, IIB will load any .jar file you add at the following locations:

/var/mqsi/shared-classes : Any jar file you place here will be accessible to all Nodes on your system.

/var/mqsi/config/IIBNODE/hared-classes : any jar file you place here will ONLY be accessible by the all EGs under this node only. A quick note: sometimes, you may not see this the shared-classes directory right under the node directory. In that case you must create it manually and it stays there until you manually delete it if no longer need

/var/mqsi/config/IIBNODE/EG/shared-classes : any jar file you place here will ONLY be accessible by all applications deployed to this EG only. A quick note: sometimes, you may not see this the shared-classes directory right under the EG directory. In that case you must create it manually and it stays there until you manually delete it if no longer need
The .jar file you place in any of those directories will be loaded by the broker internal classloader on start up.
PS. If you started the broker before adding any .jar file at any of those locations, just know that the .jar file will not be available for use at runtime. To correct this you need to CYCLE the broker.

B- Adding jar file to broker archive
You can also add a jar file to a broker archive directly following these steps.
Use 7zip or any archive file editor to open the BAR file. Inside you will see one “META-INF” and one or more .zip files each containing your applications. Please, note that if your bar file has .bar extension, you can simply rename it to .zip without making any change to the file name itself. Otherwise your application will not work
If you place the .jar file at the same level as the “META-INF” directory, all application deployed on the EG will have access to the jar file.
However, if you open any of your application file with .zip extension and place at the same level as all other files/directory in the application zip file, only that application will have access to the .jar file.
PS. Just remember to save your changes and rename the main bar file with .bar extension you changed earlier to keep things consistent.

C- Adding jar file to broker archive via toolkit
It is also possible to add .jar file to a BAR file directly in the toolkit. To do so, first drag and drop your jar file from anywhere on your computer into the IIB toolkit workspace. You can drag and drop it on Independent Resources directory or onto the application directory (IIB will automatically move this jar file to Other Resources directory, but that is fine).
Now open the BAR file you want to add the jar file to. Make sure the Prepare tab is selected and Message flows, static libraries and other message flow dependencies is also selected.
You should see a list of your application or/and lib and other resources including the jar file.
Make your application as well as the jar file, which is usually at the end of the list, are checked. You may need to scroll to the end of the list. After you finish with your selection, click Build and Save.
If the build and save is successful, then your jar file is also packaged with your application and will be made available to the application in runtime.