简体   繁体   English

JavaCompiler类路径

[英]JavaCompiler classPath

I try to use JavaCompiler to compile source code. 我尝试使用JavaCompiler编译源代码。

class A{int i;}; 
class B extends A{i = 5;};

The problem is even if they are in the same folder, When compiling class B, JavaCompiler still can't find Class A. 问题在于,即使它们位于同一文件夹中,在编译类B时,JavaCompiler仍然找不到类A。

So, I am wondering the problem is I didn't add the path of the folder to classPath. 因此,我想知道问题是我没有将文件夹的路径添加到classPath中。

I don't know how to do it in java code, So didn't give it a shot. 我不知道如何在Java代码中执行此操作,因此没有尝试。

Thanks for any help. 谢谢你的帮助。

You need to set the class path for the compile task. 您需要设置编译任务的类路径。

Have a look at the answer over here: 看看这里的答案:

another point of view would be to generate directly the bytecode using one of the famous tools for such task like ASM, JavaAssist, SERP or any other one..... It could be a very good way to avoid : - path problems - to have a finer control on the process (if you have javac errors you will be obliged to parse the stream to raise thme into your application) - improve the whole process performance 另一观点是使用一种著名的工具(例如ASM,JavaAssist,SERP或任何其他工具)直接生成字节码,这可能是避免以下问题的一种非常好的方法:-路径问题-对流程进行更好的控制(如果遇到javac错误,则必须解析流以将thme提高到应用程序中)-提高整个流程的性能

But it adds some complexity... Like often it's a trade off 但这增加了一些复杂性……通常,这是一种折衷

extend the classpath to the current directoy. 将类路径扩展到当前目录。

You can do that via the -classpath option or the CLASSPATH variable. 您可以通过-classpath选项或CLASSPATH变量来实现。

-claspath=. 

or 要么

CLASSPATH=.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM