- Blog post about Liberty and WebSockets
- StackOverflow answer that explains in detail how to write the pom.xml for web module 3.1
- StackOverflow answer that complements the previous one
Create a Maven project
This could be created manually, but Eclipse is good at this :)-
File → New → Maven Project
-
Check Use default Workspace location
Click next
-
Select the
http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository
Catalog
Select thecom.ibm.tools.archetype
webapp-jee7-liberty
Click next
-
Enter a Group Id:
com.ibm.jp.myproject
Enter a Artifact Id:myproject
Enter Package:com.ibm.jp.myproject
Click Finish
pom.xml
ArtifactDescriptorException: Failed to read artifact descriptor for com.ibm.tools.target:was-liberty:pom:LATEST: VersionResolutionException: Failed to resolve version for com.ibm.tools.target:was-liberty:pom:LATEST: Could not find metadata com.ibm.tools.target:was-liberty/maven-metadata.xml in local (/Users/paulbastide/.m2/repository)
Modify the pom.xml
-
To get rid of above error add the following to
pom.xml
<repositories> <repository> <id>maven online</id> <name>maven repository</name> <url>https://repo1.maven.org/maven2/</url> </repository> <repository> <id>liberty maven online</id> <name>liberty maven repository</name> <url>http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/</url> </repository> </repositories>
- Setup to use Dynamic Web Module 3.1
Add the following to
pom.xml
<plugin> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin>
also<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>
Also we need to make sure 3.1 is setup properly inweb.xml
(For other versions check Katsumi Kokuzawa's Blog)<!DOCTYPE xml> <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> <display-name>Servlet 3.1 Web Application</display-name> </web-app>
- Setup to use Java 7 or 8 (needed for Dynamic Web Module 3.1)
For Java 7<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin>
For Java 8 we need to use the 3.5.1 version of the plugin<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin>
Update the project
After all the changes we just do right click in the project Maven → Update Project ...If we check the Project Facets we should have
- Dynamic Web Module 3.1
- Java 1.8
- JAX-RS(Rest Web Services) 2.0
Here is a copy of the full pom.xml and web.xml files :)
0 comments :
Post a Comment