Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 环境路径-终端OSX_Macos_Environment Variables - Fatal编程技术网

Macos 环境路径-终端OSX

Macos 环境路径-终端OSX,macos,environment-variables,Macos,Environment Variables,我可以直接在terminal中运行java-classpath命令而不会出现问题,但只要我尝试在cron中执行该命令,它就会抛出以下错误: Usage: java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file) where options include:

我可以直接在terminal中运行java-classpath命令而不会出现问题,但只要我尝试在cron中执行该命令,它就会抛出以下错误:

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 (implies -server, only for x86_64)
    -client       to select the "client" VM
    -server       to select the "server" VM
    -jvm          is a synonym for the "client" VM  [deprecated]
    -hotspot      is a synonym for the "client" VM  [deprecated]
                  The default VM is client.

    -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`
用法:java[-options]类[args…] (执行一个类) 或java[-options]-jar jarfile[args…] (执行jar文件) 其中包括: -d32使用32位数据模型(如果可用) -d64如果可用,则使用64位数据模型(暗示-服务器,仅适用于x86_64) -客户端选择“客户端”虚拟机 -选择“服务器”虚拟机的服务器 -jvm是“客户机”VM的同义词[已弃用] -hotspot是“客户端”VM的同义词[已弃用] 默认VM是客户端。 -cp -类路径 A:目录、JAR档案的单独列表, 和压缩档案以搜索类文件。 -D= 设置系统属性 -详细[:类| gc | jni] 启用详细输出` 研究告诉我,这可能是一个环境路径问题?在使用terminal vs cron时,如何判断我的路径

我正从cron中使用java,crontab类似于:


03****java-classpath/Users/tb582/Desktop/sample1.jar:/Users/tb582

只需在cron中指定整个路径:

键入“哪个java”

应输出类似于以下内容的内容:

/usr/bin/java

我怀疑这会解决问题。从OP(java用法)中的输出可以明显看出,cron发现一个
java
二进制文件很好。添加到cron
/usr/bin/java
上,现在它的
30 20****/usr/bin/java-classpath
。。。。获取此错误:
线程“main”java.lang.NoClassDefFoundError中的异常:java导致:java.lang.ClassNotFoundException:java位于java.net.URLClassLoader$1.run(URLClassLoader.java:202)位于java.security.AccessController.doPrivileged(本机方法)位于java.net.URLClassLoader.findClass(urlcloader.java:190)在sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)的java.lang.ClassLoader.loadClass(ClassLoader.java:306)和java.lang.ClassLoader.loadClass(ClassLoader.java:247)
中,您应该使用/usr/bin/java-classpath(您还有第二个“java”),您是从脚本还是直接从cron调用
java
?您会在脚本(或cron调用)中发布消息吗?