Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8331493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:25:53+00:00 2026-06-09T02:25:53+00:00

class Main { public static void main(String[] args) { …. } } Starting the

  • 0
class Main {
    public static void main(String[] args) {
        ....
    }
}

Starting the program through the shell: java Main works as expected but starting the program through ant:

<target name="run" depends="cmp">
    <java classname="Main" classpath="."/>
</target>`

causes this error:

java.lang.IllegalAccessException: Class org.apache.tools.ant.taskdefs.ExecuteJava can not access a member of class Main with modifiers "public static"

JLS Section 12.3.3 Resolution of Symbolic References:

IllegalAccessError: A symbolic reference has been encountered that
specifies a use or assignment of a field, or invocation of a
method, or creation of an instance of a class, to which the code
containing the reference does not have access because the field or
method was declared private, protected, or default access (not
public), or because the class was not declared public.

So org.apache.tools.ant.taskdefs.ExecuteJava can’t execute the method because it’s enclosing class is private, but if I start the jvm pointed at a .class with a private method, it doesn’t go through the same security mechanism?

This question is similar but I still don’t understand

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:25:54+00:00Added an answer on June 9, 2026 at 2:25 am

    The answer is all in the question you linked to. When you run it through the JVM it has access to absolutely everything regardless of access level. When you run it through ant, which itself is another java program, it has to obey by the same rules as any other program – which means that it cannot see your main method.

    If you declare your class as public class Main the problem should go away.

    As to why the jvm has made this decision to allow access to private classes when starting is another matter indeed. As per the specification

    12.1.4 Invoke Test.main

    Finally, after completion of the initialization for class Test (during
    which other consequential loading, linking, and initializing may have
    occurred), the method main of Test is invoked. The method main must be
    declared public, static, and void. It must accept a single argument
    that is an array of strings. This method can be declared as either

    public static void main(String[] args) or public static void
    main(String… args)

    This specifically states that the method must be public but says nothing about the class in questions, which why it works when you invoke main through the VM directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package GC; import java.util.Scanner; public class main { public static void main(String args[]) {
In this Java code: public class Main { public static void main(String[] args) {
Java code: import javax.swing.Timer; class Main { public static void main(String args[]) { MyListener
import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) {
import java.io.UnsupportedEncodingException; import java.util.Arrays; public class Main { public static void main(String[] args) {
The following trivial Java code: public class Main { public static void main(String[] args)
import java.util.Arrays; import java.util.*; class Main { public static void main(String[] args) { }
public class Main { public static void main(String[] args){ Class2 class2Object = new Class2();
class Test { public static void main(String[] args) throws Exception { Test t =
class D { public static void main(String args[]) { Integer b2=128; Integer b3=128; System.out.println(b2==b3);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.