# Java Jar files

### Steps to build and zip Java jar files:

* It is highly recommended to build the chaincode inside docker containers with the hyperledger fabric runtime environment images to avoid any conflicts with versions of the programming language and the operating systems.\
  For building java for fabric v2.5, hyperledger/fabric-javaenv:2.5 can be used
* Example: Asset Transfer Go Chaincode: <https://github.com/spydra-tech/fabric-java-externalcc-sample/tree/main>
* Make sure to update build.gradle file to include the plugin - **com.github.johnrengelman.shadow** and add **shadowJar** section with **basename** parameter as **chaincode**. Create **manifest** section inside **shadowJar** with attribute: **Main-Class** with the **ContractBootstrap** class’s path (refer external chaincode documentation of spydra).<br>

Steps:&#x20;

* Navigate to the root of the java source code
* Use the command to build the .jar file “/gradlew build shadowJar -x test” .jar/.jar(s) will be created in the path “build/libs”\
  ![](https://640808362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5jDaQI2dLzXe5VgQBNFE%2Fuploads%2FAE5ElCoUqv6GrFD6btSV%2FScreenshot%202024-06-26%20at%204.30.56%20PM.png?alt=media\&token=9001233f-932a-4e35-a5ce-7a0701f545de)
* Use the command to build the .jar file “/gradlew build shadowJar -x test” .jar will be created in the path “build/libs”
* If you want to zip the asset-transfer-basic chaincode, select the chaincode.jar file and zip it. For java, .jar files are expected to be present inside the zip at the root path. (Eg: When opening the zip file on windows, it should not contain another directory, rather the chaincode.jar file should be present)
* META-INF folder can also be included in the zip file, select the chaincode.jar file and META-INF folder and zip it.\
  ![](https://640808362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5jDaQI2dLzXe5VgQBNFE%2Fuploads%2FuWnoKqgec9ZfOQ9lAHdJ%2FScreenshot%202024-06-26%20at%204.31.09%20PM.png?alt=media\&token=0b690fd0-9049-41a7-beee-6f6653f41604)<br>
