如何编译具有 jar 依赖项的 java 文件? [英] How do I compile a java file that has jar dependencies?

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

问题描述

我有一个帮助库,我写它放在 Apache Commons 之上,当我尝试对它进行 javac(以便我可以将它变成一个 jar)时,它很合理地抱怨说它不知道我在做什么指的是当我参考 commons.jar 中的内容时.

I have a helper lib that I wrote to sit on top of Apache Commons, and when I try to javac it (so that I can make it into a jar) it complains, quite reasonably, that it has no idea what I'm talking about when I make reference to the stuff that's in the commons.jar.

如何包含一个 jar 以便 javac 可以编译?

How does one include a jar so as that javac can compile?

推荐答案

对于 windows:

For windows:

javac -cp ".;/dir/commons.jar;/dir/more_jar_files.jar" MyClass.java

对于 unix 或 mac(感谢 Dawood 的提示):

For unix or mac (thanks for the tip Dawood):

javac -cp ".:/dir/commons.jar:/dir/more_jar_files.jar" MyClass.java

这意味着:

javac -cp <path to jar> MyClass.java

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

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