Home > Blockchain >  mvn exec:java - The specified mainClass doesn't contain a main method with appropriate signatur
mvn exec:java - The specified mainClass doesn't contain a main method with appropriate signatur

Time:09-14

I have a maven project with one sub-module. If when I run mvn compile exec:java -Dexec.mainClass=<name> it give the error in title. Project structure and poms are as follows:
file structure:

akka-topics-java
├── pom.xml
└── up-and-running
    ├── pom.xml
    ├── src
           main/java/....

parent pom:

<?xml version="1.0" encoding="UTF-8"?>

    <!-- boilerplate for project and modelVersion -->

    <groupId>akka-topics-java</groupId>
    <artifactId>examples</artifactId>
    <version>1.0.0</version>
    <packaging>pom</packaging>

    <!-- Other stuff: <name>, some <properties>, <dependencies> and <dependencyManagement> -->

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>
        </plugins>
    </build>
</project>

Child pom:

<?xml version="1.0" encoding="UTF-8"?>

<!-- boilerplate for project and modelVersion -->

    <artifactId>up-and-running</artifactId>
    <version>1.0.0</version>

    <parent>
        <groupId>akka-topics-java</groupId>
        <artifactId>examples</artifactId>
        <version>1.0.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <name>Chapter 2: Up and Running</name>
</project>

The interesting part though, is when I change from exec:java to exec:exec and change the configuration a bit, it works.
If I change the plugin in parent pom like this:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>3.1.0</version>
    <configuration>
        <executable>java</executable>
        <arguments>
            <argument>-cp</argument>
            <classpath/>
            <argument>${file}</argument>
        </arguments>
    </configuration>
</plugin>

and execute mvn compile exec:exec -Dfile=<name> it works.
Note 1: I run all these commands after cd up-and-running.
Note 2: This is not really a java project. It's full of java files that are independent and each have their public static void main.
Note 3: The full project is here

CodePudding user response:

It seems for maven-exec-plugin to "exec:java some class", the class needs to be public. I didn't specify any, so my class was package private.

  • Related