非 Java 源“在类路径上”?

发布于 2025-01-04 15:09:27 字数 391 浏览 1 评论 0原文

在工作中,我们的 Java 应用程序使用各种非 Java“源”(输入)文件(XML、属性文件等)进行运行时配置。

我听说同事使用诸如“log4j.properties 位于类路径上吗?”之类的措辞。

很明显,他们的意思是:Java 可以“看到”资源吗? 如果我们谈论的是本地运行的代码(在 Eclipse 内),那么文件必须位于 Eclipse 运行的位置。工作台可以找到它们。如果我们谈论从 CI 服务器自动构建项目,那么在该服务器上运行的 Ant 必须能够找到/查看这些资源。

我的问题:对于非 Java 源来说,这是正确的 Java 术语吗?还是这只是我工作场所使用的习惯用法? 不是类的东西怎么会这样呢?存在于路径上?!?

At work our Java applications use all sorts of non-Java "source" (input) files (XML, properties files, etc.) for runtime configuration.

I've heard co-workers use verbiage like "is log4j.properties on the classpath?"

It's obvious that what they mean by this is: can Java "see" the resource? If we're talking about code running locally (inside Eclipse), then the files must be in a location where the Eclipse workbench can find them. If we're talking about automatically building a project from a CI server, then the Ant running on that server must be able to find/see those resources.

My question: is this proper Java terminology for non-Java sources, or is this just a idiom used at my place of work? How can something that isn't a class exist on the class path?!?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流殇 2025-01-11 15:09:27

不,它们确实意味着(而且非常正确)类路径,它是目录或 JAR 文件的集合,JVM 在其中搜索类以及要访问的图像和配置文件等资源通过类似 Class.getResourceAsStream()

这实际上是为 Java 应用程序部署资源的首选方法,因为它不需要配置应用程序来查找资源,也不依赖于应用程序的“安装目录”(这在 Java 中不是一个流行的概念) Java 世界,因为当您的应用程序在应用程序服务器中运行时,它有点混乱)。

No, they really do mean (and very correctly so) the classpath, which is a collection of directories or JAR files in which the JVM searches for classes and also for resources like image and configuration files to be accessed via mechanisms like Class.getResourceAsStream().

This is actually the preferred way to deploy resources for a Java application, since it does not require the application to be configured so it can find the resources, nor does it depend on the application's "installation directory" (which is not a popular concept in the Java world, since it's kinda mushy when your application is running in an app server).

离旧人 2025-01-11 15:09:27

类路径只是 JVM 在尝试解析资源时查看的路径集合,无论它是否是源文件。如果您查看 资源的 Java 文档,它会显示

...定位系统资源可能涉及搜索 CLASSPATH 中的条目

所以我认为说“CLASSPATH 上有这样那样的资源吗?”是完全有效的。此外,它表达了要点,我想不出更好的方式来提出这个问题。

The classpath is just the collection of paths the JVM looks at when trying to resolve the a resource, whether it is a source file or not. If you look at the Java documentation for resources it says

...locating a system resource may involve searching the entries in the CLASSPATH

So I think it is perfectly valid to say "is such-and-such resource on the CLASSPATH?" Besides, it gets the point across and I can't think of a better way to ask the question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文