是否可以编译一个java文件而不提供它的依赖? [英] Is it possible to compile a java file without providing its depedencies?

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

问题描述

有一个java文件,它有一些依赖jar。但现在,我没有这些jar,我必须将其编译为.class文件。



是否可以这样做?






UPDATE



感谢您的回答。 / p>

首先,我想我们可以为缺少的依赖项创建一些存根,这很容易,但是很无聊。因为我们可以创建存根而不丢失存根,使编译器快乐,为什么我们不能让工具自动执行?该工具不需要创建存根,但读取java文件,收集信息,然后构建.class文件。



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

  import aaa。* 
import bbb。

public class Hello {
世界世界;
}



我们不知道类World是否在包aaa 或bbb。如果我们不熟悉缺失的依赖,我们甚至不知道如何为类World创建一个存根。



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