【问题标题】:Environment Path - Terminal OSX环境路径 - 终端 OSX
【发布时间】:2012-05-18 20:59:33
【问题描述】:

我可以直接在终端中运行 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`

研究告诉我这可能是环境路径问题?使用终端与 cron 时如何判断我的路径是什么?

我直接从 cron 调用 java,crontab 类似于:

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

【问题讨论】:

  • 您是从脚本调用java 还是直接从cron 调用?你会发布脚本(或 cron 调用)吗?

标签: macos environment-variables


【解决方案1】:

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

输入“哪个java”

应该输出类似这样的东西:

/usr/bin/java

【讨论】:

  • 我怀疑这会解决问题。从 OP(java 用法)的输出中可以明显看出,cron 找到了一个 java 二进制文件就好了。
  • 添加到 cron /usr/bin/java 所以现在是 30 20 * * * * /usr/bin/java java -classpath .... 收到此错误:Exception in thread "main" java.lang.NoClassDefFoundError: java Caused by: java.lang.ClassNotFoundException: java at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
  • 你应该在那里使用 /usr/bin/java -classpath(你有第二个'java')
猜你喜欢
  • 2014-08-23
  • 2017-03-18
  • 2014-08-05
  • 2017-01-15
  • 2011-08-25
  • 1970-01-01
  • 1970-01-01
  • 2014-09-01
  • 1970-01-01
相关资源
最近更新 更多