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

There is a java file in which there are some dependency bans. But now I do not have these cans, and I have to compile it into a .class file.

Can this be done?


UPDATE

Thank you for your responses.

At first I thought that we could create some stubs for missing dependencies, which is easy but boring. Since we can create stubs without gaps to make the compiler happy, why can't we make the tool automatically? The tool does not need to create stubs, but it reads a java file, collects information, and then creates .class files.

But if the "import" in the java file contains "*", this will be a problem:

import aaa.* import bbb.* public class Hello { World world; } 

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

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

+7
source share
4 answers

You can go crazy and manually process the required dependencies as stubs that do nothing except the compiler is happy.

+9
source

Not. I'm sorry. To compile you will need all the dependencies in the classpath.

+5
source

Not. But you can provide comprehensive versions of dependency class files if only a few classes that the code you are trying to compile use directly.

Then theoretically, if you take a .class file that compiles and places real dependencies in the pathpath with it, your application will work using the correct (not passed prohibition) dependency classes.

+3
source

Before compiling a file, it always looks for any dependencies. but you said that you do not have such cans!

see if you can remove the dependency relationship for this project / file, and then try to compile it. try it!

+1
source

All Articles