如何使用外部库JAR在终端中运行Java程序 [英] How to run Java program in terminal with external library JAR

查看:286
本文介绍了如何使用外部库JAR在终端中运行Java程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该很简单,但我以前从未做过,也没有找到任何解决方案。

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屋!

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