Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yukihane opened this issue Sep 1, 2022 · 2 comments
Open

Comments

@yukihane
Copy link

yukihane commented Sep 1, 2022

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>
@pzygielo
Copy link
Contributor

pzygielo commented Sep 1, 2022

exec:java executes main method of given class in existing JVM. Unless requested class is in org.codehaus.mojo.exec - it has to be public I belive.

Use exec:exec to execute Main.main in external java process.

@bmalinowsky
Copy link

This is likely a regression, it works with v1.5.0. Probably due to using MethodHandles.publicLookup() in #119. Having main in a package-private visible class is valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants