Ant - Java Command - IllegalAccessException

I need to run a java class using ant. But when I run the class file, it throws an IllegalAccessException.

this is my ant code:

<target name="test">

    <java classname="A" classpath=".">
    </java>
</target>

I got this exception when I run this target script.

[java] java.lang.IllegalAccessException: Class org.apache.tools.ant.taskdefs.ExecuteJava can not access a member of class A with modifiers "public static"
     [java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:180)

This is my java program.

class A
{
    public static void main(String[] args) 
    {
        System.out.println("Hello java!");
    }
}

Where am I mistaken?

Thanks, Srinivasan R.

+3
source share
1 answer

your class A should be publicly available:

public class A {

    public static void main(String[] args) {
        System.out.println("Hello java!");
    }
}
+9
source

Source: https://habr.com/ru/post/1720043/


All Articles