Install OpenJDK.
sudo yum -y install java-1.8.0-openjdk-devel
From * About Maven * on the left side of the screen, click ** Download **.
Right-click ** Link ** in * Binary tar.gz archive * and copy the URL. --This time, use * apache-maven-3.5.4-bin.tar.gz *.
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>
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
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
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"
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]$
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] ------------------------------------------------------------------------
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] ------------------------------------------------------------------------
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] ------------------------------------------------------------------------
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] ------------------------------------------------------------------------
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
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>
Regenerate the package.
mvn clean
mvn package
Run: ** OK! **
LANG=C java -jar target/myapp-1.0-SNAPSHOT.jar
Hello World!
Don't miss it.
Recommended Posts