mojohaus / mojohaus/exec-maven-plugin

An default visibility class, has main method, occurs error on execution

Open
#336 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
191
Forks
111
Avg merge
1d 21h
Merged PRs (30d)
4

Description

When executing mvn clean compile exec:java, following error occurs:

[INFO] --- exec-maven-plugin:3.1.0:java (default-cli) @ package-visibility ---
[WARNING] 
java.lang.Exception: The specified mainClass doesn't contain a main method with appropriate signature.
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:283)
    at java.lang.Thread.run (Thread.java:833)
Caused by: java.lang.IllegalAccessException: symbolic reference class is not accessible: class Main, from class org.codehaus.mojo.exec.ExecJavaMojo$1 (unnamed module @4425dfee)
    at java.lang.invoke.MemberName.makeAccessException (MemberName.java:955)
    at java.lang.invoke.MethodHandles$Lookup.checkSymbolicClass (MethodHandles.java:3686)
    at java.lang.invoke.MethodHandles$Lookup.resolveOrFail (MethodHandles.java:3646)
    at java.lang.invoke.MethodHandles$Lookup.findStatic (MethodHandles.java:2588)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:276)
    at java.lang.Thread.run (Thread.java:833)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.152 s
[INFO] Finished at: 2022-09-01T23:19:46+09:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.1.0:java (default-cli) on project package-visibility: An exception occurred while executing the Java class. The specified mainClass doesn't contain a main method with appropriate signature.: symbolic reference class is not accessible: class Main, from class org.codehaus.mojo.exec.ExecJavaMojo$1 (unnamed module @4425dfee) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

On the other hand, java src/main/java/Main.java command does well.

I think a main class doesn't need to be public.

RESOURCES

src/main/java/Main.java:

class Main {
    public static void main(final String[] args) {
        System.out.println("Hello, world!");
    }
}

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.github.yukihane.examples</groupId>
  <artifactId>package-visibility</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <exec-maven-plugin.version>3.1.0</exec-maven-plugin.version>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>${exec-maven-plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>java</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <mainClass>Main</mainClass>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/main/java/Main.java and pom.xml, then trace how the exec-maven-plugin's java goal loads and invokes the configured mainClass. Reproduce with mvn clean compile exec:java and compare it with java src/main/java/Main.java. Done means a package-private Main class with a public static main method executes successfully through Maven.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.