2.- Create a java program for java 8
By default the JRE System Library y set to J2SE-1.5, and the code complains because this is not compatible, so in the pom we can specify the java version.
One modified the pom, update the pom, the result is the JRE System Library node change to JavaSE-1.8, and the code stop complain.
Now test the code selecting the class and run as application.
From terminal (Windows -> Show View -> Terminal -> click on icon open terminal
and type mvn clean compile.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maven.lab</groupId>
<artifactId>mavenjavaversion</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.maven.lab.MavenJavaVersion</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
From Terminal type mvn clean compile.
$ mvn clean compile
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.maven.lab:mavenjavaversion:jar:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 18, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] -------------------< com.maven.lab:mavenjavaversion >-------------------
[INFO] Building mavenjavaversion 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mavenjavaversion ---
[INFO] Deleting C:\Users\bext\Documents\workspaceSTS448\mavenjavaversion\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mavenjavaversion ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mavenjavaversion ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform
And mvn install
$ mvn install
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.maven.lab:mavenjavaversion:jar:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 18, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] -------------------< com.maven.lab:mavenjavaversion >-------------------
[INFO] Building mavenjavaversion 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mavenjavaversion ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mavenjavaversion ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mavenjavaversion ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ mavenjavaversion ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ mavenjavaversion ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mavenjavaversion ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mavenjavaversion ---
[INFO] Installing C:\Users\bext\Documents\workspaceSTS448\mavenjavaversion\target\mavenjavaversion-0.0.1-SNAPSHOT.jar to C:\Users\bext\.m2\repository\com\maven\lab\mavenjavaversion\0.0.1-SNAPS
[INFO] Installing C:\Users\bext\Documents\workspaceSTS448\mavenjavaversion\pom.xml to C:\Users\bext\.m2\repository\com\maven\lab\mavenjavaversion\0.0.1-SNAPSHOT\mavenjavaversion-0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.891 s
[INFO] Finished at: 2020-10-02T22:33:21-05:00
[INFO] ------------------------------------------------------------------------
And Run it from the Terminal
$ cd target
bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/mavenjavaversion/target
$ java -jar mavenjavaversion-0.0.1-SNAPSHOT.jar
aaa1
abc1
eot
No hay comentarios:
Publicar un comentario