一个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.

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

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.

Thanks in advance,

-Aidiakapi

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

解决方案

You need to have the jar(s) which contains all the things your class depends on to compile it.

You can then compile the Class with

javac -classpath jar1:jar2 mypackage.MyNewClass

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 ;)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值