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

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

问题描述

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

This should be simple but I have never done it before and didn't find any solution.

我目前正在使用 Eclipse 来编写我的程序,该程序导入了一些外部 JAR 库,例如谷歌数据 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

看看这里设置Classpath

这篇关于如何使用外部库 JAR 在终端中运行 Java 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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