如何在linux中的classpath中添加多个jar文件 [英] How to add multiple jar files in classpath in linux

查看:1403
本文介绍了如何在linux中的classpath中添加多个jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我对linux和命令行都很陌生,而且对java来说还是新手。我有一个实习建立一个java程序。我终于在我的机器(Windows)上完成了它,现在我必须将它迁移到linux机器进行测试,然后让它作为可执行文件运行。我已经做了很多关于linux和阅读类路径的阅读和研究,但仍然很难完全理解。它只是没有点击我。任何人都可以使用示例以简化的方式解释类路径的目的吗?对我来说最令人困惑的一个方面实际上是定义jar的物理路径。我是从usr开始的,还是只需要从jvm文件夹开始?如果重要,我的java程序不在jvm文件夹中。任何人都可以为我解释一下吗?

Okay, I'm very new to linux and command line, and fairly new to java. I got an internship building a java program. I finally got it done on my machine (windows) and now I have to migrate it to a linux machine to test and then have it run as an executable. I have done much reading and researching on linux and understanding classpaths but it is still all very hard to fully comprehend. It's just not clicking for me yet. Can anyone explain the purpose of classpath in a simplified way using examples? One of the most confusing aspects to me is actually defining the physical path to the jar. Do I start all the way from usr or do I only need to begin from the jvm folder? If it matters, my java program is not located in the jvm folder. Can anyone shed some light for me?

编辑:非常感谢你们的帮助,我不能说我完全清楚但我的理解我的情况要好得多。

thank you guys very much for your help, I can't say that I'm fully in the clear but my understanding of my situation is a lot better.

推荐答案

你使用 -classpath 论点。您可以使用相对路径或绝对路径。这意味着您可以使用相对于当前目录的路径,或者您可以使用从根 / 开始的绝对路径。

You use the -classpath argument. You can use either a relative or absolute path. What that means is you can use a path relative to your current directory, OR you can use an absolute path that starts at the root /.

示例:

bash$ java -classpath path/to/jar/file MyMainClass

在此示例中, main 函数位于 MyMainClass 并将包含在jar文件中的某个位置。

In this example the main function is located in MyMainClass and would be included somewhere in the jar file.

编译时需要使用 javac

示例:

bash$ javac -classpath path/to/jar/file MyMainClass.java

您还可以通过环境指定类路径变量,请遵循此示例

You can also specify the classpath via the environment variable, follow this example:

bash$ export CLASSPATH="path/to/jar/file:path/tojar/file2"
bash$ javac MyMainClass.java

对于任何通常很复杂的java项目应查找名为 build.xml

For any normally complex java project you should look for the ant script named build.xml

这篇关于如何在linux中的classpath中添加多个jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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