如何使用外部库JAR在终端中运行Java程序 [英] How to run Java program in terminal with external library JAR
问题描述
这应该很简单,但我以前从未做过,也没有找到任何解决方案。
This should be simple but I have never done it before and didn't find any solution.
我目前正在使用Eclipse编写我的程序代码,外部JAR库,如google data api库。我可以使用Eclipse来编译/构建/运行程序。
I am currently using Eclipse to code my program, which imports some external JAR library such as google data api library. I can use Eclipse to compile/build/run the program.
但是现在我想在终端中运行它,那么我应该把那些JAR文件放在哪里,以及如何构建并运行程序?
But now I want to run it in terminal, so where should I put those JAR files, and how to build and run the program?
谢谢!
推荐答案
你可以执行:
1) javac -cp / path / to / jar / file Myprogram.java
2) java -cp。:/ path / to / jar / file Myprogram
所以,假设终端中的当前工作目录
是 src / Report /
So, lets suppose your current working directory
in terminal is src/Report/
javac -cp src/external/myfile.jar Reporter.java
java -cp .:src/external/myfile.jar Reporter
看看这里设置类路径
这篇关于如何使用外部库JAR在终端中运行Java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!