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.
本文标签:
版权声明:本文标题:java - Why can't I use the same class path for my compile command versus my run command when using JEP-458? - Stack Over 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741999604a2410741.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论