[JAVA] Maven on CentOS 7 tutorial

References and wisdom of ancestors

procedure

  1. Install OpenJDK.

    sudo yum -y install java-1.8.0-openjdk-devel
    
  2. Go to Maven – Welcome to Apache Maven.

  3. From * About Maven * on the left side of the screen, click ** Download **.

  4. Right-click ** Link ** in * Binary tar.gz archive * and copy the URL. --This time, use * apache-maven-3.5.4-bin.tar.gz *.

  5. Download Maven. If you are using Tera Term, the link will be pasted by right clicking.

    cd /usr/local/src; pwd
    sudo curl -LO <URL>
    
  6. Deploy Maven.

    cd ..; pwd
    gunzip -c src/apache-maven-3.5.4-bin.tar.gz | sudo tar -xpf -
    sudo ln -sv apache-maven-3.5.4 apache-maven
    
  7. Set PATH to Maven.

    cd; pwd
    cp -aiv .bash_profile .bash_profile.`date +%Y%m%d`
    echo 'PATH=/usr/local/apache-maven/bin:${PATH}' >> .bash_profile
    
  8. Log in again and make sure you can use the mvn command.

    mvn -version
    
    Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-18T03:33:14+09:00)
    Maven home: /usr/local/apache-maven
    Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/jre
    Default locale: ja_JP, platform encoding: UTF-8
    OS name: "linux", version: "3.10.0-862.11.6.el7.x86_64", arch: "amd64", family: "unix"
    
  9. Create a template for the project.

    mkdir -v /var/tmp/maven
    cd /var/tmp/maven; pwd
    mvn archetype:generate
    
    [INFO] Scanning for projects...
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom (3.9 kB at 2.6 kB/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom
    (Omission)
    2244: remote -> xyz.luan.generator:xyz-generator (-)
    Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 1252:★ Press Enter
    Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
    1: 1.0-alpha-1
    2: 1.0-alpha-2
    3: 1.0-alpha-3
    4: 1.0-alpha-4
    5: 1.0
    6: 1.1
    7: 1.3
    Choose a number: 7:★ Press Enter
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.3/maven-archetype-quickstart-1.3.pom
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.3/maven-archetype-quickstart-1.3.pom (1.6 kB at 7.1 kB/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-bundles/1.3/maven-archetype-bundles-1.3.pom
    (Omission)
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.3/maven-archetype-quickstart-1.3.jar (7.0 kB at 30 kB/s)
    Define value for property 'groupId': ★ "com.myapp"Enter
    Define value for property 'artifactId': ★ "myapp"Enter
    Define value for property 'version' 1.0-SNAPSHOT: :★ Press Enter
    Define value for property 'package' com.myapp: :★ Press Enter
    Confirm properties configuration:
    groupId: com.myapp
    artifactId: myapp
    version: 1.0-SNAPSHOT
    package: com.myapp
     Y: :★ Press Enter
    [INFO] ----------------------------------------------------------------------------
    [INFO] Using following parameters for creating project from Archetype: maven-archetype-quickstart:1.3
    [INFO] ----------------------------------------------------------------------------
    [INFO] Parameter: groupId, Value: com.myapp
    [INFO] Parameter: artifactId, Value: myapp
    [INFO] Parameter: version, Value: 1.0-SNAPSHOT
    [INFO] Parameter: package, Value: com.myapp
    [INFO] Parameter: packageInPathFormat, Value: com/myapp
    [INFO] Parameter: package, Value: com.myapp
    [INFO] Parameter: version, Value: 1.0-SNAPSHOT
    [INFO] Parameter: groupId, Value: com.myapp
    [INFO] Parameter: artifactId, Value: myapp
    [INFO] Project created from Archetype in dir: /var/tmp/maven/myapp
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 03:48 min
    [INFO] Finished at: 2018-09-28T16:37:18+09:00
    [INFO] ------------------------------------------------------------------------
    [ansible@centos7-02 maven]$
    
  10. Verify.

    cd myapp; pwd
    mvn validate
    
    [INFO] Scanning for projects...
    [INFO]
    [INFO] --------------------------< com.myapp:myapp >---------------------------
    [INFO] Building myapp 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.372 s
    [INFO] Finished at: 2018-09-28T16:38:15+09:00
    [INFO] ------------------------------------------------------------------------
    
  11. Compile.

    mvn compile
    
    [INFO] Scanning for projects...
    [INFO]
    [INFO] --------------------------< com.myapp:myapp >---------------------------
    [INFO] Building myapp 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/3.0.2/maven-resources-plugin-3.0.2.pom
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/3.0.2/maven-resources-plugin-3.0.2.pom (7.1 kB at 4.4 kB/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/30/maven-plugins-30.pom
    (Omission)
    Downloaded from central: https://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/2.0-M7/qdox-2.0-M7.jar (315 kB at 321 kB/s)
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 1 source file to /var/tmp/maven/myapp/target/classes
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 28.664 s
    [INFO] Finished at: 2018-09-28T16:39:58+09:00
    [INFO] ------------------------------------------------------------------------
    
  12. Test.

    mvn test
    
    [INFO] Scanning for projects...
    [INFO]
    [INFO] --------------------------< com.myapp:myapp >---------------------------
    [INFO] Building myapp 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/2.20.1/maven-surefire-plugin-2.20.1.pom
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/2.20.1/maven-surefire-plugin-2.20.1.pom (5.2 kB at 2.9 kB/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire/2.20.1/surefire-2.20.1.pom
    (Omission)
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit4/2.20.1/surefire-junit4-2.20.1.jar (82 kB at 280 kB/s)
    [INFO]
    [INFO] -------------------------------------------------------
    [INFO]  T E S T S
    [INFO] -------------------------------------------------------
    [INFO] Running com.myapp.AppTest
    [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.259 s - in com.myapp.AppTest
    [INFO]
    [INFO] Results:
    [INFO]
    [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 19.793 s
    [INFO] Finished at: 2018-09-28T16:41:10+09:00
    [INFO] ------------------------------------------------------------------------
    
  13. Generate a package.

    mvn package
    
    [INFO] Scanning for projects...
    [INFO]
    [INFO] --------------------------< com.myapp:myapp >---------------------------
    [INFO] Building myapp 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/3.0.2/maven-jar-plugin-3.0.2.pom
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/3.0.2/maven-jar-plugin-3.0.2.pom (6.2 kB at 3.7 kB/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/3.0.2/maven-jar-plugin-3.0.2.jar
    (Omission)
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-compress/1.11/commons-compress-1.11.jar (426 kB at 277 kB/s)
    [INFO] Building jar: /var/tmp/maven/myapp/target/myapp-1.0-SNAPSHOT.jar
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 14.051 s
    [INFO] Finished at: 2018-09-28T16:42:26+09:00
    [INFO] ------------------------------------------------------------------------
    
  14. Run: ** Error! **

    ls -l target/myapp-1.0-SNAPSHOT.jar
    LANG=C java -jar target/myapp-1.0-SNAPSHOT.jar
    
    no main manifest attribute, in target/myapp-1.0-SNAPSHOT.jar
    
  15. Modify pom.xml.

    cp -aiv pom.xml pom.xml.`date +%Y%m%d`
    vi pom.xml
    diff -u pom.xml.`date +%Y%m%d` pom.xml
    
    --- pom.xml.20180928    2018-09-28 16:37:18.062624925 +0900
    +++ pom.xml     2018-09-28 16:46:09.944109262 +0900
    @@ -50,6 +50,15 @@
             <plugin>
               <artifactId>maven-jar-plugin</artifactId>
               <version>3.0.2</version>
    +         <configuration>
    +            <archive>
    +              <manifest>
    +               <addClasspath>true</addClasspath>
    +               <classpathPrefix>lib/</classpathPrefix>
    +               <mainClass>com.myapp.App</mainClass>
    +              </manifest>
    +            </archive>
    +         </configuration>
             </plugin>
             <plugin>
               <artifactId>maven-install-plugin</artifactId>
    
  16. Regenerate the package.

    mvn clean
    mvn package
    
  17. Run: ** OK! **

    LANG=C java -jar target/myapp-1.0-SNAPSHOT.jar
    
    Hello World!
    

Don't miss it.

Recommended Posts

Maven on CentOS 7 tutorial
Enable Openjdk10 and maven on CentOS
OpenVPN on CentOS 8
Docker installation on CentOS 6
Use perltidy on CentOS 8
Install Golang on CentOS 8
Try OpenLiteSpeed on CentOS8
Install Neo4j 4.1.3 on centOS
Tomcat v8 on CentOS7
Install Vertica 10.0 on CentOS 6.10
Zabbix 5 installation on CentOS 8
Use mod_auth_cas on CentOS 8
Install PostgreSQL 12 on Centos8
Install nginx on centOS7
Install Python 3 on CentOS 7
Install kuromoji on CentOS7
Use bat on Centos.
Jetty v8 on CentOS7
OpenJDK installation on CentOS 7
Install Mattermost on CentOS 7
Install PostGIS 2.5.5 on CentOS7
Install jpndistrict on CentOS 7
Install Redmine 4.1.1 on CentOS 7
Smokeping Install on CentOS7
Install PostgreSQL 13 on CentOS 7.5
Try RabbitMQ + PHP on CentOS
Make exFat available on CentOS 7
Install OpenFOAM v2006 on CentOS
Set up Gitolite on CentOS 7
Install Jenkins on Docker's CentOS
Install Apache on CentOS on VirtualBox
Introducing Let's Encrypt on CentOS 7
Java version change on CentOS
Install Ruby 2.7 on CentOS 7 (SCL)
Perform log rotation on centos
maven
Try DPDK20 SDK on CentOS7 ①Install
CI for Maven project on AppVeyor
How to deploy Laravel on CentOS 7
Install Ruby 2.5 on CentOS 7 using SCL
Install Java Open JDK 8 on CentOS 7
Try putting CentOS 8 on Raspberry Pi 3
WordPress with Docker Compose on CentOS 8
Upgrade from MYSQL5.7 to 8.0 on CentOS 6.7
How to install MariaDB 10.4 on CentOS 8
Install apache 2.4.46 from source on CentOS7
Steps to install MySQL 8 on CentOS 8
Use the iostat command on CentOS 8
I tried installing CentOS 8 on ESXi 6.7
Steps to install devtoolset-6 on CentOS 7
Use Docker CE (official) on CentOS 8
Install Java 9 on windows 10 and CentOS 7
Develop gRPC on Windows + Java 7 + Maven 2
I installed F-Revo CRM 7.3 on CentOS 7.7
Try DPDK20 SDK on CentOS7 (2) Control DPDK driver
Build Maven repository on AWS S3 service
Install samba4 from source code on CentOS8
Set up ImpressPages 5.0 with LAMP on CentOS 7.3
Countermeasures for FDclone build failure on CentOS 8
Change JDK and Tomcat versions on CentOS
Install the webmail client Rainloop on CentOS 8