理解java命令行



有人能帮我理解下面的java cmd行在做什么吗(分解后更容易阅读(?我在我们的AV中发现了这个,不知道这个cmd作为一个整体做什么。

从我的谷歌搜索中,我发现对于-DACTIVE=true-D设置了一个系统属性值。在这种情况下,我的理解是,它将ACTIVE值设置为true。。?

我还了解-classpath在指定的目录中搜索类文件。

不幸的是,对于com.zerog.lax.LAX,我找不到它的作用。任何帮助都是值得的。

"C:UsersuserAppDataLocalTempI1644615473Windowsresourcejrebinjava.exe" -DACTIVE=true 

-classpath "C:UsersuserAppDataLocalTempI1644615473InstallerDataIAClasses.zip;

C:UsersuserAppDataLocalTempI1644615473InstallerDataExecute.zip;

C:UsersuserAppDataLocalTempI1644615473WindowsInstallerDataExecute.zip;
C:UsersuserAppDataLocalTempI1644615473InstallerDataResource1.zip;

C:UsersuserAppDataLocalTempI1644615473WindowsInstallerDataResource1.zip;

C:UsersuserAppDataLocalTempI1644615473InstallerData;

C:UsersuserAppDataLocalTempI1644615473WindowsInstallerData;" 

com.zerog.lax.LAX 

"C:/Users/user/AppData/Local/Temp/I1644615473/Windows/setup.lax" 

"C:/Users/user/AppData/Local/Temp/laxF375.tmp"

基本上有四个部分:

  1. java命令及其选项(在本例中为-D,它设置了一个任意的"属性";运行中的程序可能会想要这个(

  2. 类路径,告诉在哪里找到执行所需的所有代码。它是目录和/或jar文件的列表。

  3. 要运行的类——在本例中是类com.zerog.lax.lax,它可以在类路径中列出的位置找到,并且必须包含一个合适的main((方法。

  4. 要传递到com.zerog.lax.lax.的main((的参数

直接从java -help:

C:UsersHector>java -help
Usage: java [-options] class [args...]
(to execute a class)
or  java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32          use a 32-bit data model if available
-d64          use a 64-bit data model if available
-server       to select the "server" VM
The default VM is server.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose:[class|gc|jni]
enable verbose output
-version      print product version and exit
-version:<value>
Warning: this feature is deprecated and will be removed
in a future release.
require the specified version to run
-showversion  print product version and continue
-jre-restrict-search | -no-jre-restrict-search
Warning: this feature is deprecated and will be removed
in a future release.
include/exclude user private JREs in the version search
-? -help      print this help message
-X            print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.

  1. -D<name>=<value>设置系统属性。在您的情况下:ACTIVE=true事情是这样的:如果"ACTIVE";不是已知的系统属性,必须在某个位置定义它。对于Maven项目,我会在POM中设置它们。以下是您在Maven中的操作方法:https://stackoverflow.com/a/3231981/2851311
  2. -classpath-cp是为正在运行的应用程序指定类路径的首选方式。为什么这是首选方式?因为,如果你想从多台机器上执行一个程序,你必须在每一台机器上设置类路径,或者只需在命令行指令中使用-classpath-cp选项创建一个脚本,你就不必担心目标系统没有正确配置来找到正在执行的编译单元。以下是关于使用这些选项的更多主题:https://docs.oracle.com/javase/tutorial/essential/environment/paths.html

这些信息对您有什么用处

当您想从目录中执行java.exe时,操作系统(OS(必须知道在哪里可以找到此可执行文件。系统中可能有许多具有相同名称的文件。操作系统解决了这个问题。首先,它假设.exe文件位于您尝试执行它的同一目录中。然后,如果它在那里找不到它,它将按出现的顺序转到文件系统上类路径集中列出的所有目录,并执行它找到的第一个目录。如果没有找到匹配项,则会抛出一个错误。

您也可以提供.exe文件位置的完整路径。这是执行要使用的.exe文件的最可靠方法。

我用这个插图来帮助你理解这与你想要启动的程序是一样的。当你执行类似的操作时

C:My Directory> java HelloWorld

操作系统期望编译的单元在";我的目录";或者它可以在类路径中找到它。Java提供了一种机制,使您能够灵活地查找已编译的单元。这是通过使用-cp-classpath选项实现的。尽管如此,只有当编译的单元很简单并且没有任何依赖项和/或编译的单元不在JAR文件中时,这才有效。

如果你的程序有依赖项,同样的概念也适用:操作系统必须能够找到这些依赖项,才能在运行时加载它们。如果程序在JAR文件中,则必须直接执行JAR,而不是编译的(主(类。要执行JAR,必须使用-jar选项。

java -jar Example.jar

如果程序需要参数,也需要从命令行传递它们。有关此主题的更多信息,请点击此处:https://www.baeldung.com/java-run-jar-with-arguments

最新更新