百度智能云

All Product Document

          MapReduce

          Compile Maven Projects

          Maven Project Package Samples

          Baidu AI Cloud provides Maven project sample codes for the following components, and you can clone the codes through GitHub to design local programs: MapReduce

          Use Command Lines to Compile Maven Projects in Linux Environmento

          The Ubuntu 14.04 environment is taken as an example to introduce the installation and compilation of Maven.

          1. Install the JDK.

            1). The Maven is dependent on the Java operating environment, so you need to confirm the correct installation of JDK of version 1.4 or above before using the Maven. Execute the command sudo apt-get install openjdk-7-jdk.

            2). Set the JAVA_HOME environment variable: export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/.

            3). Verify the correct installation of JDK: java -version. The following content indicates the correct installation:

            java version "1.7.0_60"
            Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
            Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
          2. Install the Maven.

            1). Download and install the Maven: sudo apt-get install maven.

            2). Verify the correct installation of Maven: mvn -version. The following content indicates the correct installation:

            Apache Maven 3.0.5
            Maven home: /usr/share/maven
            Java version: 1.7.0_95, vendor: Oracle Corporation
            Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
            Default locale: en_US, platform encoding: UTF-8
            		OS name: "linux", version: "3.13.0-32-generic", arch: "amd64", family: "unix"
          3. Install the Git locally: sudo apt-get install git.
          4. Compile the Maven project and generate the jar file. In this document, the compiling of MapReduce (sample Maven project package provided by Baidu AI Cloud) is taken as an example.

            1). Use the GitHub to clone the Maven project package locally: git clone https://github.com/BCEBIGDATA/bmr-sample-java.git.

            2). cd-to-source file directory, i.e., "/{yourPath}/bmr-sample-java-master/mapreduce".

            3). Execute the compiling command mvn clean install to generate the jar package, which is stored in the target folder under the directory of the Maven project package, i.e. "/{yourPath}/bmr-sample-java-master/bmr-sample-java-master/mapreduce/target/mapreduce-1.0-SNAPSHOT.jar".

          Use Command Lines to Compile Maven Projects in Windows Environment

          Introduce the installation and compilation of Maven.

          1. Install the JDK.

            1). The Maven is dependent on the Java operating environment, so you need to confirm the correct installation of JDK of version 1.4 or above before using the Maven. Read the Java version corresponding to the bin package from the Maven official website, and then download and install JDK. The JDK in version of 1.7 is taken as an example, and the local installation path is C:\Program Files\Java\jdk1.7.0_79. Download address: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html.

            2). Set the environment variables. Open "Computer>Attributes>Advanced System Setups>Environment Variables", and then click "Create" in the "System Variables" bar to create Java environment variables:

            • Variable name: JAVA_HOME
            • Variable value: C:\Program Files\Java\jdk1.7.0_79
          2. Install the Maven.

            1). Download Maven's bin from the official website of Maven.

            2). Decompress the Maven package locally. In this example, the package is decompressed to D:/Maven, with the directory structure as follows:

            Directory of D:\Maven
            |-- bin|
            |-- conf|
            |-- core|
            |-- lib|
            |-- local|

            3). Set the environment variables. Open "Computer>Attributes>Advanced System Setups>Environment Variables", find "PATH" in the "System Variables" column and click "Edit", and enter ";%MAVEN_HOME%\bin" at the end of the variable value. Click "Create" to create Maven environment variables:

            • Variable name: MAVEN, and variable value: %MAVEN_HOME%\bin
            • Variable name: MAVEN_HOME, and variable value: D:/Maven

              4). Enter mvn -v in the local DOS environment, and the following content indicates the correct installation.

            Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-17+08:00)
            Maven home: D:\Maven204\bin\..
            Java version: 1.7.0_79, vendor: Oracle Corporation
            Java home: C:\Program Files\Java\jdk1.7.0_79\jre
            Default locale: zh_CN, platform encoding: GBK
            OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
          3. Compile the Maven project and generate the jar file. In this document, the compiling of MapReduce (sample Maven project package) is taken as an example.

          1). Locally download the example codes provided by Baidu AI Cloud. Open https://github.com/BCEBIGDATA/bmr-sample-java in the browser. Click "Clone or download>Download ZIP", and then download the package locally and decompress it.

          2). In the local DOS environment, cd to the directory of source files, i.e. "{yourPath}\bmr-sample-java-master\mapreduce".

          3). Execute the compiling command mvn clean install.

          4). The generated jar package is stored in the target folder under the directory of Maven project package, i.e., “{yourPath}\bmr-sample-java-master\bmr-sample-java-master\mapreduce\target\mapreduce-1.0-SNAPSHOT.jar”.

          Use Eclipse to Compile Maven Projects

          This document introduces how to use Eclipse to compile the sample Maven project package provided by Baidu AI Cloud, and the project package storage address is https://github.com/BCEBIGDATA/bmr-sample-java. The specific operation steps are as follows:

          1. Download the Eclipse from the official website. The Eclipse Neon.1a Release (4.6.1) is taken as an example in this document.
          2. Open the Eclipse, select "Window>Preferences>Java>Install JRE" in the menu bar, and make sure to select the JDK installed by the system.
          3. Import the example project provided by Baidu AI Cloud.

            1. Select "File>Import" in the Eclipse menu bar, select "Git>Projects from Git", and click "Next".
            2. Select "Clone URI", and then click "Next".
            3. In the URI bar, enter the Git address to clone: https://github.com/BCEBIGDATA/bmr-sample-java. Click "Next".

              image.png

            4. Keep the default configurations, and that is to create the local warehouse master and click "Next".
            5. In the Directory bar, enter the local warehouse's storage address "..{yourPath}\bmr-sample-java", and then click "Next".

              image.png

            6. After you select "Import as general project", the system automatically identifies the local warehouse address "..{yourPath}\bmr-sample-java", and you click "Next".

              image.png

            7. Keep the default project name "bmr-sample-java", and then click "Finish" to complete the project import.
          4. Compile the Maven project and output the jar file. After selecting the imported Maven project "mapreduce>pom.xml", open "Run>Run As>Maven install" in the menu bar to launch the compilation.
          5. After the successful compilation, the generated jar package is stored in the target folder under the directory of the local Maven project, i.e., "{yourPath}\bmr-sample-java\mapreduce\target\mapreduce-1.0-SNAPSHOT.jar".

          Use Netbeans to Compile Maven Projects

          1. Download and install the Netbeans of version 6.7 or above, which integrates Maven.
          2. Import the example project provided by Baidu AI Cloud.

            1). Open Netbeans, select "Team Development (M)>Git(G)>Clone" in the menu bar, and enter the example address provided by Baidu AI Cloud in the URL bar of resource pool: https://github.com/BCEBIGDATA/bmr-sample-java. Specify the local warehouse's address "..{yourPath}\bmr-sample-java", and then click "Next".

            2). Keep the default configurations, and that is to create the local warehouse master and click "Next".

            3). Keep the default configurations, and click "Finish".

            4). After the system completes the cloning of codes, you can select "Open Project" in the pop-up dialog box to view the imported project in the left project bar.

          3. Compile the Maven project and output the jar file.

            1). Open the mapreduce module. Select "bmr>Modules>mapreduce" in the left project bar, right-click and select "Open Project", and open the Maven project mapreduce.

            2). Select the opened Maven project mapreduce, and then click "Run>Clean and Build Projects" in the menu bar.

          4. After the successful compilation, the generated jar package is stored in the target folder under the directory of the local Maven project, i.e., "{yourPath}\bmr-sample-java\mapreduce\target\mapreduce-1.0-SNAPSHOT.jar".
          Previous
          Store Data to HBase
          Next
          Identity and Access Management