admin管理员组

文章数量:1316351

I've been using JEP 458 to great effect, until I ran into a weird situation today.

Here is some relevant info.

$ java --version
openjdk 24-ea 2025-03-18
OpenJDK Runtime Environment (build 24-ea+25-3155)
OpenJDK 64-Bit Server VM (build 24-ea+25-3155, mixed mode, sharing)

$ javac --version
javac 24-ea

And here is my directory hierarchy.

.
├───aa
│   └───a
│           abc.java
│
└───b
        xyz.java

Here are the files.

abc.java

$ cat a/abc.java

package a;

import b.xyz;

public class abc
{

        public static void main(final String[] args)
        {

                final xyz blah = new xyz();

        }

}

xyz.java

$ cat ../b/xyz.java

package b;

public class xyz {}

And finally, here is where I am.

$ pwd
<parent directories omitted>/aa

Ok, so, while in /aa, I wanted to run the main method of /aa/a/abc.java. Now, abc.java has an import for xyz.java which is in package b.

That package b is not currently accessible from the class path, so I added a class path option to my command.

$ java --class-path "./../" a/abc.java

Again, I am in the /aa directory, which means it will go up a level, then be at the root for b to be discoverable, to my understanding.

But when I run the command, I got this error instead.

$ java --class-path "./../" a/abc.java
a\abc.java:4: error: package b does not exist
import b.xyz;
        ^
a\abc.java:12: error: cannot find symbol
                final xyz blah = new xyz();
                      ^
  symbol:   class xyz
  location: class abc
a\abc.java:12: error: cannot find symbol
                final xyz blah = new xyz();
                                     ^
  symbol:   class xyz
  location: class abc
3 errors
error: compilation failed

Ok, so I tried to run javac instead of java.

$ javac --class-path "./../" a/abc.java

Completed with no errors. And here is my new tree output.

.
├───aa
│   └───a
│           abc.class
│           abc.java
│
└───b
        xyz.class
        xyz.java

So, javac is just fine with this, but java is not.

Am I doing something wrong? I tried multiple variants of class path parameters, all to no avail. Or is this just not supported functionality?

I guess the part that surprises me is that, if I were to remove the /aa folder, and leave it to just be /a and /b in the same level directory, then this all works.

本文标签: