开发者

Is it possible to compile a java file without providing its dependencies?

There is a java file, which has some dependencies jars. But now, I don't have those jars, and I have to compile it to a .class file.

Is it possible to do this?


UPDATE

Thanks for your answers.

At first, I thought we can create some stubs for the missing dependencies, that's easy but boring. Since we can create the stubs without missing stubs to make the compiler happy, why can't we make a tool do it automatically? The tool doesn't need to create stubs, but reads the java file, collects informations, and then builds the .class files.

But if the "import" statements in the java fi开发者_运维问答le contain "*", that will be a problem:

import aaa.*
import bbb.*

public class Hello {
   World world;
}

We don't know if the class "World" is under package "aaa" or "bbb". If we are not familiar with the missing dependencies, we even don't know how to create a stub for the class "World".

But if the "import" statements are clear, I think it's possible, but maybe no one will write such a tool


You could go crazy and hand craft the required dependencies as stubs that do nothing except keep the compiler happy.


No. Sorry. You'll need all dependncies in the classpath to compile.


No. But you could provide stubbed-out versions of the dependency class files, if it is only a handful of classes that the code your are trying to compile uses directly.

Then in theory if you take the .class file that compiles and place the real dependencies on the classpath with it your app will work using the correct (non-stubbed-out) dependency classes.


Before any file is compiled it always looks up for any dependencies. but you said you dont have those jars!!!

see if you can remove the dependencies relation for that project/file and then try to compile it. give it a try!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜