我该怎么办?
当我输入' ant'或者' ant -version'终端只显示java帮助(例如' java -h')。
有没有办法解决这个问题?
编辑:这里是终端日志:
sebastian@sebastian-virtual-machine:~$ ant Usage: java [options] <mainclass> [args...] (to execute a class) or java [options] -jar <jarfile> [args...] (to execute a jar file) or java [options] -m <module>[/<mainclass>] [args...] java [options] --module <module>[/<mainclass>] [args...] (to execute the main class in a module) Arguments following the main class, -jar <jarfile>, -m or --module <module>/<mainclass> are passed as the arguments to main class. where options include: -zero to select the "zero" VM -cp <class search path of directories and zip/jar files> -classpath <class search path of directories and zip/jar files> --class-path <class search path of directories and zip/jar files> A : separated list of directories, JAR archives, and ZIP archives to search for class files. -p <module path> --module-path <module path>... A : separated list of directories, each directory is a directory of modules. --upgrade-module-path <module path>... A : separated list of directories, each directory is a directory of modules that replace upgradeable modules in the runtime image --add-modules <module name>[,<module name>...] root modules to resolve in addition to the initial module. <module name> can also be ALL-DEFAULT, ALL-SYSTEM, ALL-MODULE-PATH. --list-modules list observable modules and exit -d <module name> --describe-module <module name> describe a module and exit --dry-run create VM and load main class but do not execute main method. The --dry-run option may be useful for validating the command-line options such as the module system configuration. --validate-modules validate all modules and exit The --validate-modules option may be useful for finding conflicts and other errors with modules on the module path. -D<name>=<value> set a system property -verbose:[class|module|gc|jni] enable verbose output -version print product version to the error stream and exit --version print product version to the output stream and exit -showversion print product version to the error stream and continue --show-version print product version to the output stream and continue --show-module-resolution show module resolution output during startup -? -h -help print this help message to the error stream --help print this help message to the output stream -X print help on extra options to the error stream --help-extra print help on extra options to the output stream -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:jdwp see also -agentlib:jdwp=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 HiDPI scaled images are automatically supported and used if available. The unscaled image filename, e.g. image.ext, should always be passed as the argument to the -splash option. The most appropriate scaled image provided will be picked up automatically. See the SplashScreen API documentation for more information @argument files one or more argument files containing options -disable-@files prevent further argument file expansion To specify an argument for a long option, you can use --<name>=<value> or --<name> <value>. sebastian@sebastian-virtual-machine:~$ java Usage: java [options] <mainclass> [args...] (to execute a class) or java [options] -jar <jarfile> [args...] (to execute a jar file) or java [options] -m <module>[/<mainclass>] [args...] java [options] --module <module>[/<mainclass>] [args...] (to execute the main class in a module) Arguments following the main class, -jar <jarfile>, -m or --module <module>/<mainclass> are passed as the arguments to main class. where options include: -zero to select the "zero" VM -cp <class search path of directories and zip/jar files> -classpath <class search path of directories and zip/jar files> --class-path <class search path of directories and zip/jar files> A : separated list of directories, JAR archives, and ZIP archives to search for class files. -p <module path> --module-path <module path>... A : separated list of directories, each directory is a directory of modules. --upgrade-module-path <module path>... A : separated list of directories, each directory is a directory of modules that replace upgradeable modules in the runtime image --add-modules <module name>[,<module name>...] root modules to resolve in addition to the initial module. <module name> can also be ALL-DEFAULT, ALL-SYSTEM, ALL-MODULE-PATH. --list-modules list observable modules and exit -d <module name> --describe-module <module name> describe a module and exit --dry-run create VM and load main class but do not execute main method. The --dry-run option may be useful for validating the command-line options such as the module system configuration. --validate-modules validate all modules and exit The --validate-modules option may be useful for finding conflicts and other errors with modules on the module path. -D<name>=<value> set a system property -verbose:[class|module|gc|jni] enable verbose output -version print product version to the error stream and exit --version print product version to the output stream and exit -showversion print product version to the error stream and continue --show-version print product version to the output stream and continue --show-module-resolution show module resolution output during startup -? -h -help print this help message to the error stream --help print this help message to the output stream -X print help on extra options to the error stream --help-extra print help on extra options to the output stream -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:jdwp see also -agentlib:jdwp=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 HiDPI scaled images are automatically supported and used if available. The unscaled image filename, e.g. image.ext, should always be passed as the argument to the -splash option. The most appropriate scaled image provided will be picked up automatically. See the SplashScreen API documentation for more information @argument files one or more argument files containing options -disable-@files prevent further argument file expansion To specify an argument for a long option, you can use --<name>=<value> or --<name> <value>. sebastian@sebastian-virtual-machine:~$
@StephenC感谢您的帮助,如果我正在运行&#39; sudo ant&#39;它正在运行,但是如果我和用户一起运行它会打印出来&#39; java -h&#39;。
有什么方法可以解决这个问题吗?
请参阅terminal-log:
sebastian@sebastian-virtual-machine:/usr/share/ant/bin$ sudo ant Buildfile: build.xml does not exist! Build failed sebastian@sebastian-virtual-machine:/usr/share/ant/bin$ sudo ant -version Apache Ant(TM) version 1.10.3 compiled on March 29 2018 sebastian@sebastian-virtual-machine:/usr/share/ant/bin$ ant -version Usage: java [options] <mainclass> [args...] (to execute a class) or java [options] -jar <jarfile> [args...] (to execute a jar file) or java [options] -m <module>[/<mainclass>] [args...] java [options] --module <module>[/<mainclass>] [args...] (to execute the main class in a module) Arguments following the main class, -jar <jarfile>, -m or --module <module>/<mainclass> are passed as the arguments to main class. where options include: -zero to select the "zero" VM -cp <class search path of directories and zip/jar files> -classpath <class search path of directories and zip/jar files> --class-path <class search path of directories and zip/jar files> A : separated list of directories, JAR archives, and ZIP archives to search for class files. -p <module path> --module-path <module path>... A : separated list of directories, each directory is a directory of modules. --upgrade-module-path <module path>... A : separated list of directories, each directory is a directory of modules that replace upgradeable modules in the runtime image --add-modules <module name>[,<module name>...] root modules to resolve in addition to the initial module. <module name> can also be ALL-DEFAULT, ALL-SYSTEM, ALL-MODULE-PATH. --list-modules list observable modules and exit -d <module name> --describe-module <module name> describe a module and exit --dry-run create VM and load main class but do not execute main method. The --dry-run option may be useful for validating the command-line options such as the module system configuration. --validate-modules validate all modules and exit The --validate-modules option may be useful for finding conflicts and other errors with modules on the module path. -D<name>=<value> set a system property -verbose:[class|module|gc|jni] enable verbose output -version print product version to the error stream and exit --version print product version to the output stream and exit -showversion print product version to the error stream and continue --show-version print product version to the output stream and continue --show-module-resolution show module resolution output during startup -? -h -help print this help message to the error stream --help print this help message to the output stream -X print help on extra options to the error stream --help-extra print help on extra options to the output stream -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:jdwp see also -agentlib:jdwp=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 HiDPI scaled images are automatically supported and used if available. The unscaled image filename, e.g. image.ext, should always be passed as the argument to the -splash option. The most appropriate scaled image provided will be picked up automatically. See the SplashScreen API documentation for more information @argument files one or more argument files containing options -disable-@files prevent further argument file expansion To specify an argument for a long option, you can use --<name>=<value> or --<name> <value>. sebastian@sebastian-virtual-machine:/usr/share/ant/bin$
答案 0 :(得分:3)
证据是/usr/bin/ant
以某种方式得到了java
命令的硬链接或符号链接或别名。
在Linux上,ant
命令是shell脚本,(实际)java
命令是本机代码可执行文件。请尝试以下方法:
$ type ant
$ file `which ant`
如果它显示为ELF二进制文件,请使用Linux命令将可执行文件与java可执行文件进行比较。
如果它显示为shell脚本,则应首先less
它以查看它是否是正确的脚本。然后,您可以调整脚本(例如,通过临时添加set -x
)来查看运行ant -version
时实际执行的操作。
type ant
还应该告诉您ant
是shell函数还是别名。
但最重要的是,你的系统或你的shell环境中的某些内容有点过时了。
答案 1 :(得分:0)
检查Ant build.xml
中是否有默认任务,该任务运行或链接到java
命令。
有时,此默认任务会尝试在环境中或磁盘上查找“配置”可能的java
命令。
例如调用
java ${something}
缩减为
java
${something}
评估为“”。
如果这个Ant文件被移动了,通常它将找不到配置,并且java命令将作为一个裸java
调用启动,调用帮助输出。