macos 在基于 UNIX 的系统中存储我的 Java 库和应用程序的常规位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2707793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:54:30  来源:igfitidea点击:

The conventional location for storing my Java libraries and applications in UNIX based systems

javalinuxmacosunix

提问by Behrang Saeedzadeh

I usually store the Java applications and JAR files that I download from the Web in the ~/Java folder on my computer (an OS X machine). I have been doing this since the days when I was a Windows user. However I think in UNIX based systems user local apps are conventionally stored in another directory. I have a feeling that this directory should either be /usr/local/, /usr/local/USERNAME, /opt/local, or /opt/local/USERNAMEbut I am not sure. Any ideas which directory can I use for this purpose?

我通常将从 Web 下载的 Java 应用程序和 JAR 文件存储在我的计算机(OS X 机器)上的 ~/Java 文件夹中。从我还是 Windows 用户开始,我就一直在这样做。但是我认为在基于 UNIX 的系统中,用户本地应用程序通常存储在另一个目录中。我有一种感觉,这个目录应该是/usr/local/, /usr/local/USERNAME, /opt/local, 或者/opt/local/USERNAME但我不确定。我可以为此目的使用哪个目录的任何想法?

Please note that, I am talking about archive files that I download from the Web, unpack and use locally and not programs that have installation scripts or MacPorts, etc.

请注意,我说的是我从 Web 下载、解压并在本地使用的存档文件,而不是具有安装脚本或 MacPorts 等的程序。

采纳答案by Thorbj?rn Ravn Andersen

There isn't any blessed way to do it. You may, however, run into having multiple versions of a jar, and then it just goes downhill from there.

没有任何幸运的方法可以做到这一点。但是,您可能会遇到一个 jar 的多个版本,然后它就会从那里走下坡路。

I usually download the jars I need as a distribution, and unpack it to its own folder, and then add the jars to the projects I need them for in my IDE. For libraries a common approach is to use Maven and its dependency handling.

我通常会下载我需要的 jar 作为发行版,然后将其解压到自己的文件夹中,然后将这些 jar 添加到我的 IDE 中需要它们的项目中。对于库,一种常见的方法是使用 Maven 及其依赖项处理。

So, my suggestion is to keep your current way of doing it, if you like that, but have each project in its own folder, like

所以,我的建议是保持你目前的做法,如果你喜欢的话,但将每个项目放在自己的文件夹中,比如

~/Java/jakarta-commons-net-1.1.8/commons-net.jar

回答by Tom Anderson

The para-answer is that you shouldn't be downloading jars by hand at all, you should be using Gradle, Ivy, Maven, or something similar to manage your jars for you. These tools take a simple specification of your dependencies as input, and go and find, download, store, and make available all the necessary jar files. This takes a little bit of getting used to, but are rather wonderful once you're in the swing of it.

最重要的是,您根本不应该手动下载 jar,而应该使用GradleIvyMaven或类似的东西来为您管理 jar。这些工具将您的依赖项的简单规范作为输入,然后查找、下载、存储和提供所有必需的 jar 文件。这需要一点时间来适应,但是一旦你开始使用它就会非常棒。

A direct answer, though, is that on orthodox unix, these files belong in /usr/local/share. usrbecause they're read-only data that is not part of the base operating system, localbecause they are not being supplied by the operating system (which owns the rest of /usr), and sharebecause jar files are architecture-independent.

不过,一个直接的答案是,在正统的 unix 上,这些文件属于/usr/local/share. usr因为他们是只读数据,是不是基本操作系统的一部分,local因为它们是不被操作系统(其拥有的其余部分提供/usr),以及share因为jar文件体系结构无关。

Note that on FreeBSD, the 'ports' package management system puts files in /usr/local, but i believe it shares it with the local administrator. There isn't some other location where purely local files go.

请注意,在 FreeBSD 上,'ports' 包管理系统将文件放入/usr/local,但我相信它与本地管理员共享它。没有其他位置可以存放纯本地文件。

If the system has a convention for where package-managed jars go, then copy that under /usr/local. For example, on Ubuntu, there is /usr/share/java, so you should use /usr/local/share/java.

如果系统对包管理的 jar 的位置有约定,则将其复制到/usr/local. 例如,在 Ubuntu 上,有/usr/share/java,所以你应该使用/usr/local/share/java.

Further, if the system has a convention for handling versions, copy that. Again, on Ubuntu, jars are all stored in one directory, with version numbers in the name, but with a versionless symlink pointing to the default/latest version. So, i have a file at /usr/share/java/xstream-1.3.1.jar, and a symlink at /usr/share/java/xstream.jarpointing to it. I'd use the same approach in /usr/local/share/java.

此外,如果系统有处理版本的约定,请复制该约定。同样,在 Ubuntu 上,jar 都存储在一个目录中,名称中带有版本号,但带有指向默认/最新版本的无版本符号链接。所以,我有一个文件/usr/share/java/xstream-1.3.1.jar/usr/share/java/xstream.jar指向它的符号链接。我会在/usr/local/share/java.

Now, that's for orthodox unix. You're on OS X, which is not orthodox unix. Still, the principles apply: find how the system stores jars it provides, and transpose that into a user-managed filesystem space.

现在,这适用于正统的 unix。您使用的是 OS X,它不是正统的 unix。尽管如此,这些原则仍然适用:找到系统如何存储它提供的 jar,并将其转换为用户管理的文件系统空间。

回答by user151019

Apple have a notegiving /Library/Java/Extensions as the directory for shared jars and ~/Library/Java/Extensions for jars just for yourself. These paths are on the classpath.

Apple 有一个注释,将 /Library/Java/Extensions 作为共享 jar 的目录,而 ~/Library/Java/Extensions 则为您自己的 jar 目录。这些路径在类路径上。

The jars can be anywhere as long as that directory is on your class path. (I use a version of Thorbj?rn Ravn Andersen's style I use ~/Library/Jar/jakarta-commons-net-1.1.8/commons-net.jar)

只要该目录在您的类路径上,jar 就可以在任何地方。(我使用 Thorbj 的版本?rn Ravn Andersen 的风格我使用 ~/Library/Jar/jakarta-commons-net-1.1.8/commons-net.jar)

See Tom Anderson's answer for a better way to do it using ivy etc

请参阅 Tom Anderson 的答案,了解使用 ivy 等的更好方法

回答by xenoterracide

You might wish to read the Filesystem Hierarchy Standard/opt or /usr/local are probably appropriate but you should read there FHS definitions first.

您可能希望阅读文件系统层次结构标准/opt 或 /usr/local 可能是合适的,但您应该首先阅读 FHS 定义。

回答by Mikhail T.

On FreeBSD systems the location is ${LOCALBASE}/share/java-- and subdirectories thereof. Not that all software-ports respect it, but they should.

在 FreeBSD 系统上,该位置是${LOCALBASE}/share/java-- 及其子目录。并不是所有的软件端口都尊重它,但他们应该这样做。

LOCALBASEis usually /usr/local-- unless overwritten by the system administrator.

LOCALBASE通常是/usr/local——除非被系统管理员覆盖。