是否可以在不提供依赖项的情况下编译Java文件? [英] Is it possible to compile a java file without providing its dependencies?

查看:144
本文介绍了是否可以在不提供依赖项的情况下编译Java文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个Java文件,其中包含一些依赖项jar。但是现在,我没有那些jars,必须将其编译为.class文件。



是否可以这样做?






更新



感谢您的回答。



起初,我认为我们可以为缺少的依赖项创建一些存根,这很简单,但很无聊。由于我们可以创建存根而不会丢失存根以使编译器满意,因此为什么我们不能使工具自动完成呢?该工具不需要创建存根,而是读取java文件,收集信息,然后构建.class文件。



但是如果 import语句在Java文件中包含 *,这将是一个问题:

  import aaa。* 
import bbb。*

公共类您好{
世界世界;
}

我们不知道 World类是否在 aaa软件包下或 bbb。如果我们不熟悉缺少的依赖项,那么我们甚至都不知道如何为世界类创建存根。



但是如果 import语句很清楚,我认为这是可能的,但是也许没人会写出这样的工具


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 file 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.

这篇关于是否可以在不提供依赖项的情况下编译Java文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆