1

The chaincode container cannot start (after committing to the channel) due to the following error:

Error: Main method not found in class mypackage.MyChaincodeClass, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

I'm working with fabric-java-chaincode 2.2.3 on a 2.2.2 network.

So the problem seems self explanatory but I'm using the example on Maven java chaincode on GitHub as a guideline and I adapted the maven shade plugin configuration:

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <finalName>chaincode</finalName>
                            <transformers>
                                <transformer                                    
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>mypackage.MyChaincodeClass</mainClass>
                                </transformer>
                            </transformers>
                            <filters>
                                <filter>                                    
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

the tree of my project is the following:

.
└── project-repo/
    ├── chaincode/
    │   ├── src/
    │   │   └── main/
    │   │       └── java/
    │   │           └── mypackage/
    │   │               └── MyChaincodeClass.java
    │   └── pom.xml
    └── another-module/
        └── ...

I tried to start the uber-jar using java -jar chaincode.jar and I get the same error as the one printed in the container logs.

The manifest in the generate uber-jar looks good to me:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven 3.6.3
Built-By: ultracode
Build-Jdk: 11.0.9
Main-Class: mypackage.MyChaincodeClass

The chaincode uses only the @Contract and @Transaction annotation and implements the ContractInterface interface (I'm not using the @Default annotation beacause this chaincode is not the default one in the channel)

ultracode
  • 107
  • 1
  • 8

2 Answers2

0

you need to mention the complete directory from chaincode Example:

    <mainClass>chaincode.example.SimpleChaincode</mainClass>
  • Thanks for the answer but is unclear how this can solve the problem. My package structure and class name are different from the github example. The chaincode class `MyChaincodeClass` is located in the package `mypackage` so the complete path is `src/main/java/mypackage/MyChaincodeClass.java`. The pom file is at the same level as the `src` like any other vanilla maven project. – ultracode Aug 17 '22 at 12:44
  • yes you have two options one is you can change the directory structure to shorten it and two is to mention the complete package example: chaincode.src.main.java.mypackage.MyPackageClass – ibrahimq21 Aug 17 '22 at 12:47
  • hopefully it will resolve the current issue. – ibrahimq21 Aug 17 '22 at 12:49
0

The maven-shade-plugin transformer configuration the mainClass tag must be set like this :

<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
   <mainClass>org.hyperledger.fabric.contract.ContractRouter</mainClass>
</transformer>

I was missled by the Maven example for the 2.2 release in which the maven shade plugin transformer is set like this:


<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
   <mainClass>chaincode.example.SimpleChaincode</mainClass>
</transformer>

In later versions the error was fixed, also the Gradle example in the same release has the correct setting.

ultracode
  • 107
  • 1
  • 8