Ubuntu Crontab Java version does not match the problem resolution unsupported Major.minor version 51.0

Source: Internet
Author: User

Because the Lucene4.9 requires a minimum Java version of Java7, so the JAVA6 has been used to upgrade, or the following error will be reported:

Exception in thread "main" java.lang.unsupportedclassversionerror:org/apache/solr/client/solrj/solrserverexception : Unsupported Major.minor version 51.0 at Java.lang.ClassLoader.defineClass1 (Native Method) at Java.lang.Cla Ssloader.defineclass (classloader.java:634) at Java.security.SecureClassLoader.defineClass (Secureclassloader.java : 142) at Java.net.URLClassLoader.defineClass (urlclassloader.java:277) at java.net.urlclassloader.access$000 ( urlclassloader.java:73) at Java.net.urlclassloader$1.run (urlclassloader.java:212) at Java.security.AccessCon Troller.doprivileged (Native Method) at Java.net.URLClassLoader.findClass (urlclassloader.java:205) at java.la Ng.        Classloader.loadclass (classloader.java:321) at Sun.misc.launcher$appclassloader.loadclass (Launcher.java:294) At Java.lang.ClassLoader.loadClass (classloader.java:266) at JAVA.LANG.CLASS.FORNAME0 (Native Method) at Java . lang. Class.forName (Class.java: 188) at Com.guahao.task.CrontabTask.main (crontabtask.java:30) 

So the upgrade, in the Ubuntu/etc/profile directory under the configuration of Java7 Java_home,path and the like.

However, when performing some of Java-jar's tasks through crontab, the error is reported, and it is not a problem to execute directly at the command line. Obviously, the Java version used by crontab is inconsistent with the Java version used by the normal user.

This can be done in the following ways:

    1. Before executing the jar package through Java-jar, you can make a path to Java, for example:
      /usr/lib/jvm/jdk1.7.0_65/bin/java-jar
    2. Add the configuration of environment variables such as Java_home,path in Crontab, for example:
      Path=/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-6-sun/binjava_home=/usr/lib/jvm/java-6-sun

problem can be solved.
PS: Why crontab not use the global (etc/profile) java_home configuration?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.