[英]Running Java from the windows command line
I recently asked a bout a java program I could not find the start point to and was told to look in the bat file which started it but I do not understand what it says.我最近问了一个关于 java 程序的问题,我找不到起点,并被告知要查看启动它的 bat 文件,但我不明白它在说什么。
This program runs on a tomcat server and must be running before the.jsp pages will run so they are not the starting point.该程序在 tomcat 服务器上运行,并且必须在 .jsp 页面运行之前运行,因此它们不是起点。
Can anyone explain what this means and where the program starts so I can do a step through.任何人都可以解释这意味着什么以及程序从哪里开始,以便我可以逐步完成。
D:\foo_development\server>java -Xmx256M -Djava.library.path=lib -Djava.rmi.serv
er.hostname=192.168.0.104 -Djava.rmi.server.codebase="file:/D:\foo_development\
server\foo_server.jar http://192.168.0.104:8000/foo_client_stubs/server_keycon
sole_stubs.jar" -Djava.security.policy=conf/java.policy -jar foo_server.jar 109
8 2001
This is exactly how it appears in the cmd window after I click run.bat这正是我单击 run.bat 后它在 cmd window 中的显示方式
Let's analyze the command line:我们来分析一下命令行:
java
: the executable java
:可执行文件-Xmx256M
: how much memory to use -Xmx256M
: 使用多少 memory-Djava.library.path=lib
where to find native libraries (for JNI) -Djava.library.path=lib
在哪里可以找到本地库(用于 JNI)-Djava.rmi.server.hostname=192.168.0.104 -Djava.rmi.server.codebase="file:/D:\foo_development\ server\foo_server.jar http://192.168.0.104:8000/foo _client_stubs/server_keycon sole_stubs.jar"
RMI related stuff -Djava.rmi.server.hostname=192.168.0.104 -Djava.rmi.server.codebase="file:/D:\foo_development\ server\foo_server.jar http://192.168.0.104:8000/foo _client_stubs/server_keycon sole_stubs.jar"
RMI 相关的东西-Djava.security.policy=conf/java.policy
which security policy to use -Djava.security.policy=conf/java.policy
使用哪个安全策略-jar foo_server.jar
the JAR file to execute! -jar foo_server.jar
JAR 文件执行! This is the juicy bit!109 8 2001
arguments passed to your main()
method 109 8 2001
arguments 传递给您的main()
方法So foo_server.jar
is the.jar file that gets executed.所以
foo_server.jar
是被执行的.jar 文件。 Check its META-INF/MANIFEST.MF
for a line that starts with Main-Class:
and that should tell you which class gets executed.检查它的
META-INF/MANIFEST.MF
是否有以Main-Class:
开头的行,这应该会告诉您执行了哪个 class。
D:\foo_development\server>java -Xmx256M -Djava.library.path=lib -Djava.rmi.serv
er.hostname=192.168.0.104 -Djava.rmi.server.codebase="file:/D:\foo_development\
server\foo_server.jar http://192.168.0.104:8000/foo_client_stubs/server_keycon
sole_stubs.jar" -Djava.security.policy=conf/java.policy -jar foo_server.jar 109
8 2001
This command runs foo_server.jar file with arguments 109,8,201.此命令运行带有 arguments 109,8,201 的 foo_server.jar 文件。 And all other before -jar are vm arguments to tell jvm about the different memory size like heapmemory size and aslo library path.
和之前的所有其他 -jar 是 vm arguments 告诉 jvm 关于不同的 memory 大小,如堆内存大小和 aslo 库路径。
For your main class you will find its entry in MANIFIST file as Main-class:-- foo.bar.MainClass
对于您的主要 class 您将在 MANIFIST 文件中找到它的条目作为
Main-class:-- foo.bar.MainClass
In short you have简而言之,你有
java -jar foo_server.jar
The rest is just configuration and arguments. rest 只是配置和 arguments。
In the foo_server.jar there will be a MANIFEST.MF file which contains a line like在 foo_server.jar 中会有一个 MANIFEST.MF 文件,其中包含如下行
Main-Class: com.mycompany.foo.FooMain
This is the class where main(String[])
is called when it is loaded.这是 class 在加载时调用
main(String[])
的地方。
Looking at the command:查看命令:
java
is the executable to run ( java.exe
, found on the path) java
是要运行的可执行文件( java.exe
,在路径上找到)-Xmx256M
specifies a maximum heap size of 256 megabytes -Xmx256M
指定最大堆大小为 256 MB-D
(multiple times) defines various Java system properties -D
(多次)定义各种Java系统属性-jar
means "load the given jar file, and start with the class specified by the Main-Class
attribute in its manifest -jar
表示“加载给定的 jar 文件,并从其清单中Main-Class
属性指定的 class 开始foo_server.jar
is the jar file to load foo_server.jar
是要加载的 jar 文件1098 2001
are the command line arguments to main
(so args
will be an array with elements "1098" and "2001" 1098 2001
是命令行 arguments 到main
(所以args
将是一个包含元素“1098”和“2001”的数组 The key part is the options -jar foo_server.jar
.关键部分是选项
-jar foo_server.jar
。 This tells the JRE to open that named JAR, to read the Main-Class
property from its metadata (in the archive's META-INF/MANIFEST.MF
) and execute that (starting from its static main
method, as normal).这告诉 JRE 打开名为 JAR 的文件,从其元数据中读取
Main-Class
属性(在存档的META-INF/MANIFEST.MF
中)并执行该属性(从其 static main
方法开始,正常)。
The main class of an jar can be specified in the manifest of this jar. jar 的主要 class 可以在此 jar 的清单中指定。 (@see http://download.oracle.com/javase/tutorial/deployment/jar/appman.html )
( @见 http://download.oracle.com/javase/tutorial/deployment/jar/appman.html )
In your case it is the foo_server.jar
.在您的情况下,它是
foo_server.jar
。 This jar (a jar it is just a zip) must have a folder META-INF
where the manifest is located.这个 jar(一个 jar 它只是一个 zip)必须有一个
META-INF
文件夹,清单所在的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.