如何从程序中找到JVM版本?(How to find the JVM version from a program?)
我想编写一个示例Java文件,其中我想知道类正在运行的JVM版本。 有办法吗
I want to write a sample Java file in which I want to know the JVM version in which the class is running. Is there a way?
原文:https://stackoverflow.com/questions/5103121
最满意答案
http://www.mail-archive.com/users@maven.apache.org/msg90985.html上的电子邮件交换说:
“ 这是所有的理论...也许在编写文档时,有人涉及到Maven开发,认为有一个src / main / config目录可能是有用的,因此它被包含在文档中,但由于它从未在代码中实现今天没有被使用。 “
和
“ 目录 [src / main / config] 不会显示在类路径上,所以应用程序或测试类不能读取任何内容。
所以只需使用
src/main/resources
。注意:我不知道这是否是真的(我是问题提问者),但这将解释为什么这么多人在网络上推荐用于log4j.properties的
src/main/resources
。 如果人们同意这是正确的答案,你可以让我知道(评论或投票)我把它放在这里,以拯救别人打字。The email exchange at http://www.mail-archive.com/users@maven.apache.org/msg90985.html says:
"This is all theory... Perhaps while writing the docs, someone involved with Maven development thought it might be useful to have a src/main/config directory and so it was included in docs, but since it was never implemented in the code, it is not being used today."
and
"The directory [src/main/config] doesn't show up on the classpath so the application or test classes can't read anything in it."
So just use
src/main/resources
.Note: I don't know if this is true (I'm the question asker), but that would explain why so many people on the web recommend
src/main/resources
for log4j.properties. If people agree this is the right answer could you let me know (comment or vote) I put it here to save other people the typing.
相关问答
更多-
从src / main / resources中读取NullPointerException(Reading from src/main/resources gives NullPointerException)[2022-05-21]
FileInputStream会将您传递给构造函数的文件路径加载为与Java进程的工作目录相关的文件路径。 getResourceAsStream()将从您的应用程序的类路径加载相对于文件路径。 当您使用.getClass().getResource(fileName)它认为fileName的位置与调用类的位置相同。 当您使用.getClass().getClassLoader().getResource(fileName)它认为.getClass().getClassLoader().getResourc ... -
来自src/main/resources将被放到classpath的根目录下,所以你需要获取资源: new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/config.txt"))); 您可以通过查看由maven生成的JAR / WAR文件进行验证,因为您会在档案的根目录中找到config.txt 。 Resources from src/main/resources will be put onto the r ...
-
如何在非Maven项目中拥有等效的主/资源?(How to have the equivalent of main/resources in a non-Maven project?)[2022-06-05]
将资源放在类路径上,例如,放在源目录中。 所有Maven都将src/main/resources包/目录树合并到目标类路径中,保持相同的包/文件夹布局。 Put the resources on the classpath, for example, in the source directory. All Maven does is merge the src/main/resources package/directory tree into the target classpath, maintain ... -
在eclipse中添加资源文件夹: 点击Build Path 点击Configure Build Path (或者Properties - > Java Build Path ) 点击Source Tab 点击Add Folder 点击Create new Folder To add a resource folder in eclipse: Click on Build Path Click on Configure Build Path (or Properties -> Java Build Path ...
-
http://www.mail-archive.com/users@maven.apache.org/msg90985.html上的电子邮件交换说: “ 这是所有的理论...也许在编写文档时,有人涉及到Maven开发,认为有一个src / main / config目录可能是有用的,因此它被包含在文档中,但由于它从未在代码中实现今天没有被使用。 “ 和 “ 目录 [src / main / config] 不会显示在类路径上,所以应用程序或测试类不能读取任何内容。 所以只需使用src/main/resour ...
-
一种解决方法是使用命令行参数显式指定您希望log4j使用的log4j.xml 。 -Dlog4j.configuration=file:/log4j.xml One workaround is to explicitly specify the log4j.xml that you want log4j to use using a command-line argument. -Dlog4j.configuration=file:/log4j.xml
-
一旦在pom.xml中声明显式资源,Maven就会忘记src / main / resources曾经存在过。 你现在必须明确地把它放回去:
src/main/resources **/* -
对于标题问题:通常在.war maven模块中,您将把与web相关的资源放在src / main / webapp下,而不是src / main / resources。 然后maven插件将自动拾取它们,因为它符合约定。 因此,将applicationContext.xml移动到src / main / webapp / WEB-INF 另一种选择是按照文档中的描述配置webResources 对于第二个问题,您可以查看PropertyPlaceHolderConfigurer 。 你只需要让路径正确。 ...
-
这是一个SpringBoot应用程序吗? 如果是这样,src / main / resources / static中的文件用于SpringMVC应用程序中的Web资源(模板,css,js,图像)。 建议将它们移动到不同的文件夹(或将它们保存在src / main / resources中。根据文档 ,ant样式的正则表达式模式来获取所需的文件可以正常工作。 Is this a SpringBoot app? If so, files in the src/main/resources/static is ...
-
在您的情况下, WEB-INF应包含Web描述符web.xml和Spring配置文件。 虽然Hibernate配置文件hibernate.cfg.xml和其他映射文件应该在开发时放在src/main/resources里面。 http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html/ch01.html#tutorial-firstapp 来自Hibernate的这个官方教程告诉你在src/main/resources和WEB-INF包含哪些内容的细节 ...