Search code examples
javamavenaionoan

Contract compilation failed because of an InvocationTargetException error


I'm trying to create a Java contract with Aion using Maven, but every time I try to run mvn clean install, I get the following error:

[ERROR] Failed to execute goal org.aion4j:aion4j-maven-plugin:0.6.7:postpack (default) on project LearningAion: Contract Jar post compilation failed: InvocationTargetException: NullPointerException -> [Help 1]

I recreated a project using the Maven build command: mvn archetype:generate -DarchetypeGroupId=org.aion4j -DarchetypeArtifactId=avm-archetype -DarchetypeVersion=0.20 and that project works fine.

Here's my contract code:

package AnimalHouse;

import avm.Blockchain;
import org.aion.avm.tooling.abi.Callable;

public class MyPets
{
    private static String myDogsName = "Alan.";

    @Callable
    public static String getString() {
        return myString;
    }

    @Callable
    public static void setString(String newStr) {
        myString = newStr;
    }
}

According to the Aion Docs everything should just compile. I'm not sure why this contract isn't working but when I create a brand new one it is.


Solution

  • Take a look in your project's pom.xml file for <contract.main.class>. Double check that what's between those two tags is the name of your main Java class and the package name. It you case it should be AnimalHouse.MyPets.

    <properties>
        ...
        <contract.main.class>AnimalHouse.MyPets</contract.main.class>
        ...
    </properties>