如何编译单个Java文件 [英] How to compile a single Java file

查看:552
本文介绍了如何编译单个Java文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索过这个,但我找不到或不明白我发现了什么。

现在我不是一个Java程序员,但我需要编译一个单一的Java文件到一个现有的(编译)Java程序。这个Java代码的源代码不是可用于我,因此我无法编译整个项目。

我不想反编译原始项目。

I have searched this, but I could'n find or understand what I found.
Now I'm not a Java programmer, but I have the need to compile a single Java file into an existing (compiled) Java program. The source of this Java code is not available to me, therefore I cannot compile the entire project.
I'm not interested in decompiling the original project.

如何使用JDK和javac快速做到这一点? (通过命令行是我喜欢的。)

How to quickly do this using only the JDK and javac? (Through the command line is what I prefer.)

我知道为了这样做,错误检查单个java文件外面将被禁用,因为它可以'

I understand that to do so error checking outside of the single java file will have to be disabled, because it can't read the dependencies.

提前感谢

-Aidiakapi

Thanks in advance,
-Aidiakapi

EDIT:我有JAR文件,感谢回答:)

I do have the JAR file, thanks for the answer :)

推荐答案

jar

然后你可以用

javac -classpath jar1:jar2 mypackage.MyNewClass

如果你没有访问原始的jar,你将不得不创建mock类和方法等(这不必做任何事情,只是在那里,所以你的类编译)使用IDE可以使这两个过程更容易。 (这是它的目的)。

If you have no access to the original Jars, you will have to create mock classes and method etc (which don't have to do anything, just be there so your class compiles) Using an IDE can make both processes easier. (That is what it is for ;)

这篇关于如何编译单个Java文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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