01. Let's go! Creating a Java Project
This blog has been based on the Java Brains video tutorial. It is a very interesting tutorial
In Eclipse you can see Servers as Window-View-Servers
Create a new server by clicking the right button on the Server Window and select New. Select Tomcat...
Once the server has been created, by double-clicking on it and you can select server locations
And fill Group id and Artifact Id that matches the project name
The project is generated in Eclipse
Insert the build section to the pom-xml
If we don't pretend to use "web.xml" file, the property called "failOnMissingWebXml" should be set to "false".
Our pom.xml will be:
Let's update the project by right-clicking on the project, Maven - Update Project now we can see that the Java version has been changed.
1. Install Tomcat
In Eclipse you can see Servers as Window-View-Servers
Create a new server by clicking the right button on the Server Window and select New. Select Tomcat...
Once the server has been created, by double-clicking on it and you can select server locations
2. Create a Maven Project
with File-New-Other-Maven ProjectAnd fill Group id and Artifact Id that matches the project name
The project is generated in Eclipse
3. Modifying the pom.xml
There are some changes to be done in the pom.xml:a. Changing Java version from J2SE-1-5 to JavaSE-10
Insert the build section to the pom-xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <build> <finalName>Jaxrs02</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <inherited>true</inherited> <configuration> <source>10</source> <target>10</target> </configuration> </plugin> </plugins> </build> |
b. Adding dependencies not included in Java 10 (but are included in Java 8 versions and priors)
The dependencies are:- jaxb-impl
- jaxb-core
- javax-activation
- jaxws-rijaxb-ri
Additional dependencies are used
- jaxrs-ri
- jersey-media-moxy
- lombok (for avoiding getters and setters boilerplate)
Our pom.xml will be:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | <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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.ximodante.jaxrs</groupId> <artifactId>Jaxrs02</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <properties> <failOnMissingWebXml>false</failOnMissingWebXml> <jersey.version>2.27</jersey.version> <lombok.version>1.18.2</lombok.version> <jax.version>2.3.0</jax.version> </properties> <dependencies> <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.bundles/jaxrs-ri --> <dependency> <groupId>org.glassfish.jersey.bundles</groupId> <artifactId>jaxrs-ri</artifactId> <version>${jersey.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-moxy --> <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-moxy</artifactId> <version>${jersey.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> <scope>provided</scope> </dependency> <!-- Java 9 dependencies!!! --> <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl --> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> <version>${jax.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core --> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-core</artifactId> <version>${jax.version}</version> </dependency> <dependency> <groupId>com.sun.activation</groupId> <artifactId>javax.activation</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-ri</artifactId> <version>${jax.version}</version> <type>pom</type> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-ri</artifactId> <version>${jax.version}</version> <type>pom</type> </dependency> <!-- End of Dependencies required for JAVA 9!!!! --> </dependencies> <build> <finalName>Jaxrs02</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <inherited>true</inherited> <configuration> <source>10</source> <target>10</target> </configuration> </plugin> </plugins> </build> </project> |
Let's update the project by right-clicking on the project, Maven - Update Project now we can see that the Java version has been changed.
Comentarios
Publicar un comentario