[JAVA] Tutoriel Maven sur CentOS 7

Références et sagesse des ancêtres

procédure

  1. Installez OpenJDK.

    sudo yum -y install java-1.8.0-openjdk-devel
    
  2. Accédez à Maven - Bienvenue dans Apache Maven.

  3. À partir de * À propos de Maven * sur le côté gauche de l'écran, cliquez sur ** Télécharger **.

  4. Cliquez avec le bouton droit de la souris sur ** Lien ** dans * Archive tar.gz binaire * et copiez l'URL.

  1. Téléchargez Maven. Si vous utilisez Tera Term, le lien sera collé par un clic droit.

    cd /usr/local/src; pwd
    sudo curl -LO <URL>
    
  2. Déployez 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
    
  3. Réglez le PATH sur Maven.

    cd; pwd
    cp -aiv .bash_profile .bash_profile.`date +%Y%m%d`
    echo 'PATH=/usr/local/apache-maven/bin:${PATH}' >> .bash_profile
    
  4. Reconnectez-vous et assurez-vous que vous pouvez utiliser la commande mvn.

    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"
    
  5. Créez un modèle pour le projet.

    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:★ Appuyez sur la touche Entrée
    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:★ Appuyez sur la touche Entrée
    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"Entrer
    Define value for property 'artifactId': ★ "myapp"Entrer
    Define value for property 'version' 1.0-SNAPSHOT: :★ Appuyez sur la touche Entrée
    Define value for property 'package' com.myapp: :★ Appuyez sur la touche Entrée
    Confirm properties configuration:
    groupId: com.myapp
    artifactId: myapp
    version: 1.0-SNAPSHOT
    package: com.myapp
     Y: :★ Appuyez sur la touche Entrée
    [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]$
    
  6. Vérifiez.

    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] ------------------------------------------------------------------------
    
  7. Compilez.

    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] ------------------------------------------------------------------------
    
  8. Testez.

    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] ------------------------------------------------------------------------
    
  9. Générez un 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] ------------------------------------------------------------------------
    
  10. Exécutez: ** Erreur! **

    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
    
  11. Modifiez 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>
    
  12. Régénérez le paquet.

    mvn clean
    mvn package
    
  13. Exécutez: ** OK! **

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

Ne le manquez pas.

Recommended Posts

Tutoriel Maven sur CentOS 7
Activer Openjdk10 et maven sur CentOS
Installation de Docker sur CentOS 6
Utiliser perltidy sur CentOS 8
Installez Golang sur CentOS 8
Essayez OpenLiteSpeed sur CentOS8
Installez Neo4j 4.1.3 sur centOS
Tomcat v8 sur CentOS7
Installez Vertica 10.0 sur CentOS 6.10
Installation de Zabbix 5 sur CentOS 8
Utilisez mod_auth_cas sur CentOS 8
Installez PostgreSQL 12 sur Centos8
Installez Python 3 sur CentOS 7
Installez kuromoji sur CentOS7
Jetty v8 sur CentOS7
Installation d'OpenJDK sur CentOS7
Installez PostGIS 2.5.5 sur CentOS7
Installez jpndistrict sur CentOS 7
Installez Redmine 4.1.1 sur CentOS 7
Installation de Smokeping sur CentOS7
Installez PostgreSQL 13 sur CentOS 7.5
Essayez Rabbit MQ + PHP sur CentOS
Rendre exFat disponible sur CentOS 7
Installez OpenFOAM v2006 sur CentOS
Configurer Gitolite sur CentOS 7
Installez Jenkins sur CentOS de Docker
Installez Apache sur CentOS sur VirtualBox
Changer la version java sur CentOS
Installez Ruby 2.7 sur CentOS 7 (SCL)
Effectuer la rotation des journaux avec centos
Maven
Projet CI pour Maven sur AppVeyor
Comment déployer Laravel sur CentOS 7
Installez Ruby 2.5 sur CentOS 7 en utilisant SCL
Installation de Java Open JDK 8 sur CentOS 7
Essayez de mettre CentOS 8 dans Raspberry Pi 3
WordPress avec Docker Compose sur CentOS 8
Comment installer MariaDB 10.4 sur CentOS 8
Installez apache 2.4.46 à partir des sources sur CentOS 7
Utilisez la commande iostat sur CentOS 8
J'ai essayé d'installer CentOS 8 sur ESXi 6.7
Étapes pour installer devtoolset-6 sur CentOS 7
Utiliser Docker CE (officiel) avec CentOS 8
Installez Java 9 sur Windows 10 et CentOS 7
Développer gRPC sur la série Windows + Java 7 + Maven 2
J'ai installé F-Revo CRM 7.3 sur CentOS 7.7
Créer un référentiel Maven sur les services AWS S3
Installez samba4 à partir du code source sur CentOS8
Contre-mesures pour l'échec de la construction de FDclone sur CentOS 8
Changer les versions de JDK et Tomcat sur CentOS
Installez le client de messagerie Web Rainloop sur CentOS 8