Centos 7:Maven的Java版本

时间:2017-04-14 23:42:17

标签: java maven centos7 openjdk

我在我的centos 7上安装了一个开放的jdk。我希望maven能够使用java 1.8。我不想打破机器的java。实现这一目标的最佳方法是什么?

正在运行:mvn -v

`Maven home: /usr/share/maven
 Java version: 1.7.0_131, vendor: Oracle Corporation
 Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.131-2.6.9.0.el7_3.x86_64/jre
 Default locale: en_US, platform encoding: UTF-8
 OS name: "linux", version: "3.10.0-514.10.2.el7.x86_64", arch: 
 "amd64", family: "unix"`

正在运行:java -version

`openjdk version "1.8.0_121"
 OpenJDK Runtime Environment (build 1.8.0_121-b13)
 OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)`

这是我的mvn config

正在运行:cat /usr/bin/mvn

`#!/bin/sh
if [ -f /usr/share/java-utils/java-functions ] ; then
   . /usr/share/java-utils/java-functions
   set_jvm
   set_javacmd
fi
export M2_HOME="${M2_HOME:-/usr/share/maven}"
export JAVA_HOME; $M2_HOME/bin/mvn "$@"` 

正在运行$yum search java | grep openjdk

`java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
 java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
 java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
 java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
 java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
 java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
 java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
 java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
 java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
 java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without
 java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
 java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
 java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment
 java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment
 java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
 java-1.8.0-openjdk-accessibility-debug.x86_64 : OpenJDK accessibility connector
 java-1.8.0-openjdk-debug.i686 : OpenJDK Runtime Environment with full debug on
 java-1.8.0-openjdk-debug.x86_64 : OpenJDK Runtime Environment with full debug on
 java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos
 java-1.8.0-openjdk-demo-debug.x86_64 : OpenJDK Demos with full debug on
 java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment
 java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment
 java-1.8.0-openjdk-devel-debug.i686 : OpenJDK Development Environment with full
 java-1.8.0-openjdk-devel-debug.x86_64 : OpenJDK Development Environment with
 java-1.8.0-openjdk-headless.i686 : OpenJDK Runtime Environment
 java-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environment
 java-1.8.0-openjdk-headless-debug.i686 : OpenJDK Runtime Environment with full
 java-1.8.0-openjdk-headless-debug.x86_64 : OpenJDK Runtime Environment with full
 java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation
 java-1.8.0-openjdk-javadoc-debug.noarch : OpenJDK API Documentation for packages
 java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK API Documentation compressed in
 java-1.8.0-openjdk-javadoc-zip-debug.noarch : OpenJDK API Documentation
 java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle
 java-1.8.0-openjdk-src-debug.x86_64 : OpenJDK Source Bundle for packages with`

2 个答案:

答案 0 :(得分:2)

  1. 我怀疑你通过将Maven的JRE改为Java 1.8来“破坏任何东西”。

  2. 运行 alternatives --config java以查看当前安装的JVM。理想情况下,如果您同时拥有JRE7和JRE8,则应该看到列出的两个。

  3. 只需修改您的import java.util.Arrays; public class Temp { public static class SmartQuickSortPivot { public int left; public int right; } static int[] values = {2,5,1,66,89,44,32,51,8,6}; // values to be sorted /** * split4SmartQuickSort splits the array (from first to last) into two subarrays, left and right, using the * provided splitVal. It needs to calculate on the fly the average of all the elements of the left subarray * and average of all elements of the right subarray, and store the two averages in the @pivot object. * The following implementation is only copy of the code from * the split function (from line 247) and you should enhance the function to implement what we need to calculate the averages * as the pivot for the left and right subarray. * * Please be noted that splitVal may not even exist in the array since we choose the average. * But this should not impact the correctness algorithm of splitting and sorting. * @param first * @param last * @param splitVal * @param leftRightAverages * @return */ static SmartQuickSortPivot split4SmartQuickSort(int first, int last, int splitVal, SmartQuickSortPivot leftRightAverages) { int i = first,j = last; int sumLeft = 0; int sumRight = 0; while (i < j) { while (values[i] < splitVal){ sumLeft += values[i]; i++; } while (values[j] > splitVal){ sumRight += values[j]; j--; } if (i < j) { swap(i, j); } } leftRightAverages.left = (i - first == 0) ? values[first] : sumLeft / (i - first); leftRightAverages.right = (last - j == 0) ? values[last] : sumRight / (last - j); SmartQuickSortPivot smartQuickSortPivot = new SmartQuickSortPivot(); smartQuickSortPivot.left = i; smartQuickSortPivot.right = j; return smartQuickSortPivot; } private static void swap(int i, int j) { int temp = values[i]; values[i] = values[j]; values[j] = temp; } /** * Smart quick sort allows the use of a better splitting value (the pivot value) when to split the array * into two. In this algorithm, we will use the average of the array (subarray) of all elements as the pivot. * * Each call to split (split4SmartQuickSort method), the splitValue will be passed and also the split4SmartQuickSort * will return the averages of left subarray and right subarray. The two averages, each will be used for the * following calls to smartQuickSort. * * @param first the first element * @param last the last element * @param splitVal the pivot value for splitting the array */ static void smartQuickSort(int first, int last, int splitVal) { if (first < last) { SmartQuickSortPivot splitPoint; SmartQuickSortPivot leftRightAverages = new SmartQuickSortPivot(); splitPoint = split4SmartQuickSort(first, last, splitVal, leftRightAverages); if (first < splitPoint.left) { smartQuickSort(first, splitPoint.left - 1, leftRightAverages.left); } if (last > splitPoint.right) { smartQuickSort(splitPoint.right + 1, last, leftRightAverages.right); } } } public static void main(String[] args) { /** you can either compute the average first as the first pivot or simplify choose the first one as the pivot */ smartQuickSort(0, values.length - 1, values[5]); System.out.println(Arrays.toString(values)); } } 即可指向所需的路径。

  4. 再次运行/usr/bin/mvn。您应该看到更新的配置。

答案 1 :(得分:0)

RAN:
   df= ratings.drop(['movieId', 'userId', axis=1]) df

然后:

yum install java-1.8.0-openjdk-devel

选择我的项目所需的版本。

感谢所有回复!