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

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

问题描述

有一个java文件,里面有一些依赖jar.但是现在,我没有那些 jar,我必须将其编译为 .class 文件.

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.

可以这样做吗?

更新

感谢您的回答.

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

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.

但是如果java文件中的import"语句包含*",那就有问题了:

But if the "import" statements in the java file contain "*", that will be a problem:

import aaa.*
import bbb.*

public class Hello {
   World world;
}

我们不知道类World"是在包aaa"还是bbb"下.如果我们不熟悉缺少的依赖项,我们甚至不知道如何为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".

但是如果import"语句说清楚的话,我觉得是有可能的,但是可能没人会写这样的工具

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天全站免登陆