Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Lyo/creating OSLC4J project"

< Lyo
Line 1: Line 1:
Make sure your environment is setup for OSLC4J development as instructed on [[Lyo/General_Setup_for_OSLC4J_Development | General Setup for OSLC4J development]]
+
= Eclipse Setup =
  
= Sample Project =
+
Make sure your environment is setup for OSLC4J development as instructed on [https://wiki.eclipse.org/Lyo/General_Setup_for_OSLC4J_Development General Setup for OSLC4J development]
  
As a complement when following the instructions below, this [[Media:OSLC4JSampleAdaptor.zip | sample OSLC4J project]] contains a basic but complete Eclipse project that can be used as a starting point and/or a reference.
+
= Create an OSLC4J project =
  
The project is configured with the following values:
+
The steps below guide you through the necessary steps of creating an Eclipse project with the necessary configurations to develop any OSLC4J adaptor.
  
'''ProjectName''': ''SampleAdaptor''
+
In the instructions below, we assume the following parameters:
'''PackageName''': ''your.basepackage.name''
+
  
If you desire to change the project configuration, search and replace in the files below each of the above keywords with the specific values for your project
+
* Eclipse Project Name: ''test-sample-webapp''
 +
* Base Package Name for Java Classes: ''test.sample.webapp''
  
* <code>.project</code>
+
We will here only create the code skeleton. The [https://wiki.eclipse.org/Lyo/ToolchainModellingAndCodeGenerationWorkshop Toolchain Modelling and Code Generation Workshop] can then be used to generate the necessary code to become a fully functional adaptor.
* <code>pom.xml</code>
+
* <code>adaptorModel/my.adaptorInterface</code>
+
* <code>src/main/webapp/WEB-INF/web.xml</code>
+
* <code>src/test/resources/launches/Launch SampleAdaptor.launch</code>
+
  
If you get the error "Project configuration is not up-to-date with pom.xml", simply right click on the eclipse project and select '''Maven-->Update Project...'''.
+
Creation of the skeleton consists of 2 steps:
  
= Setup an OSLC4J project =
+
# creating a Maven project from an archetype
'''Note''': This information is based on the tutorial from [[Media:The MBAT Tutorial on Implementing OSLC Consumers and Providers with OSLC4J - By Stefan Paschke ViF.pdf | The MBAT Tutorial on Implementing OSLC Consumers and Providers with OSLC4J - By Stefan Paschke ViF]].
+
# customising the generated project with the Lyo-specific configuration
  
The steps below guide you through the necessary steps of creating an Eclipse project with the necessary configurations to develop any OSLC4J adaptor.
+
== Creating a Maven project from an archetype ==
 +
 
 +
To create a Maven project from an archetype via Eclipse
 +
 
 +
# select ''File &gt; New &gt;Other''
 +
# then select ''Maven Project'' under ''Maven'' group.
 +
# Leave the ''Create a simple project'' checkbox unchecked.
 +
# Uncheck the ''Use default Workspace location'' option and point it to the project root
 +
# Press ''Next''
 +
 
 +
<!-- ![](https://wiki.eclipse.org/images/d/d5/CreateMavenAdaptorProject_Step1.png) -->
 +
[[File:CreateMavenAdaptorProject_Step1.png|frame|none|800px]]
 +
 
 +
Next, select the <code>maven-archetype-webapp</code> archetype:
 +
 
 +
<!-- ![](https://wiki.eclipse.org/images/2/26/CreateMavenAdaptorProject_Step2.png) -->
 +
[[File:CreateMavenAdaptorProject_Step2.png|frame|none|800px]]
 +
 
 +
Next, Fill in the '''Group Id''', '''Artefact Id''', and the '''Package Base'''.
 +
 
 +
* The '''Package Base''' value (<code>test.sample.webapp</code> on this page) will be used as a base package for your adaptor code.
 +
 
 +
<!-- ![](https://wiki.eclipse.org/images/d/d9/CreateMavenAdaptorProject_Step3.png) -->
 +
[[File:CreateMavenAdaptorProject_Step3.png|frame|none|800px]]
 +
 
 +
You should now have the project in Eclipse and the following folder structure:
 +
 
 +
<!-- ![](https://wiki.eclipse.org/images/c/cd/CreateMavenAdaptorProject_CodeStructure.png) -->
 +
[[File:CreateMavenAdaptorProject_CodeStructure.png|frame|none|800px]]
 +
 
 +
== Customise the project POM file ==
 +
 
 +
We now need to modify the project ''pom.xml'' file.
 +
 
 +
=== General POM changes ===
 +
 
 +
We need to make sure our project uses UTF-8 and JDK 1.8. We will also use properties to define a common version for Lyo Core and Lyo Server packages:
 +
 
 +
<source lang="xml"><properties>
 +
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 +
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 +
  <maven.compiler.source>1.8</maven.compiler.source>
 +
  <maven.compiler.target>1.8</maven.compiler.target>
 +
  <version.lyo.core>2.1.2</version.lyo.core>
 +
  <version.lyo.server>2.1.0</version.lyo.server>
 +
</properties></source>
 +
We require Java EE 6 or higher and JSTL:
 +
 
 +
<source lang="xml"><dependency>
 +
  <groupId>javax.servlet</groupId>
 +
  <artifactId>javax.servlet-api</artifactId>
 +
  <version>3.1.0</version>
 +
  <scope>provided</scope>
 +
</dependency>
 +
<dependency>
 +
  <groupId>javax.servlet</groupId>
 +
  <artifactId>jstl</artifactId>
 +
  <version>1.2</version>
 +
</dependency></source>
 +
=== Lyo package dependencies ===
 +
 
 +
an OSLC4J project will use Lyo dependencies that we need to declare. Before we can do that, we need to add the Lyo repository:
 +
 
 +
<source lang="xml">  <repositories>
 +
    <repository>
 +
      <id>lyo-releases</id>
 +
      <name>lyo-releases repository</name>
 +
      <url>https://repo.eclipse.org/content/repositories/lyo-releases/</url>
 +
    </repository>
 +
  </repositories></source>
 +
Now were are ready to add the dependencies.
 +
 
 +
Lyo uses SLF4J for logging, leaving the choice of the actual logging library to use. We will use the simplest option:
 +
 
 +
<source lang="xml"><dependency>
 +
  <groupId>org.slf4j</groupId>
 +
  <artifactId>slf4j-simple</artifactId>
 +
  <version>1.7.21</version>
 +
  <scope>runtime</scope>
 +
</dependency></source>
 +
Lyo dependencies need:
 +
 
 +
<source lang="xml"><dependency>
 +
  <groupId>org.eclipse.lyo.oslc4j.core</groupId>
 +
  <artifactId>oslc4j-core</artifactId>
 +
  <version>${version.lyo.core}</version>
 +
  <exclusions>
 +
    <exclusion>
 +
      <groupId>org.slf4j</groupId>
 +
      <artifactId>slf4j-log4j12</artifactId>
 +
    </exclusion>
 +
  </exclusions>
 +
</dependency>
 +
<dependency>
 +
  <groupId>org.eclipse.lyo.oslc4j.core</groupId>
 +
  <artifactId>oslc4j-jena-provider</artifactId>
 +
  <version>${version.lyo.core}</version>
 +
  <exclusions>
 +
    <exclusion>
 +
      <groupId>org.slf4j</groupId>
 +
      <artifactId>slf4j-log4j12</artifactId>
 +
    </exclusion>
 +
  </exclusions>
 +
</dependency>
 +
<dependency>
 +
  <groupId>org.eclipse.lyo.oslc4j.core</groupId>
 +
  <artifactId>oslc4j-wink</artifactId>
 +
  <version>${version.lyo.core}</version>
 +
</dependency>
 +
<dependency>
 +
  <groupId>org.eclipse.lyo.oslc4j.core</groupId>
 +
  <artifactId>oslc4j-json4j-provider</artifactId>
 +
  <version>${version.lyo.core}</version>
 +
</dependency></source>
 +
<blockquote>Exclusions are due to the [https://bugs.eclipse.org/bugs/show_bug.cgi?id=513477 Bug 513477]
 +
</blockquote>
 +
Finally, your adaptor might need to includes the experimental support for OAuth:
 +
 
 +
<source lang="xml"><dependency>
 +
  <groupId>org.eclipse.lyo.server</groupId>
 +
  <artifactId>oauth-core</artifactId>
 +
  <version>${version.lyo.server}</version>
 +
</dependency>
 +
<dependency>
 +
  <groupId>org.eclipse.lyo.server</groupId>
 +
  <artifactId>oauth-consumer-store</artifactId>
 +
  <version>${version.lyo.server}</version>
 +
  <exclusions>
 +
    <exclusion>
 +
      <groupId>org.slf4j</groupId>
 +
      <artifactId>slf4j-log4j12</artifactId>
 +
    </exclusion>
 +
  </exclusions>
 +
</dependency>
 +
<dependency>
 +
  <groupId>org.eclipse.lyo.server</groupId>
 +
  <artifactId>oauth-webapp</artifactId>
 +
  <version>${version.lyo.server}</version>
 +
  <type>war</type>
 +
</dependency></source>
 +
<blockquote>OAuth is enabled by default. If you want to disable it, open the generated <code>Application</code> class and do the following changes:
 +
 
 +
* comment out line <code>RESOURCE_CLASSES.add(Class.forName(&quot;org.eclipse.lyo.server.oauth.webapp.services.ConsumersService&quot;));</code>
 +
* comment out line <code>RESOURCE_CLASSES.add(Class.forName(&quot;org.eclipse.lyo.server.oauth.webapp.services.OAuthService&quot;));</code>
 +
* change <code>catch (ClassNotFoundException e)</code> to <code>catch (Exception e)</code>
 +
</blockquote>
 +
If you use OAuth or consume any resources in your Adaptor Interface, an OSLC client dependency is needed:
 +
 
 +
<source lang="xml"><dependency>
 +
  <groupId>org.eclipse.lyo.clients</groupId>
 +
  <artifactId>oslc-java-client</artifactId>
 +
  <version>${version.lyo.core}</version>
 +
  <exclusions>
 +
    <exclusion>
 +
      <groupId>org.slf4j</groupId>
 +
      <artifactId>jcl-over-slf4j</artifactId>
 +
    </exclusion>
 +
  </exclusions>
 +
</dependency></source>
 +
=== Embedded Jetty server for quick debugging ===
 +
 
 +
Finally, you should use an embedded servlet container during the debugging to simplify the development process. Jetty configuration looks the following, where the port number (''8080'' below) can be adjusted as appropriate.
 +
 
 +
<source lang="xml"><build>
 +
  <plugins>
 +
    <plugin>
 +
      <groupId>org.eclipse.jetty</groupId>
 +
      <artifactId>jetty-maven-plugin</artifactId>
 +
      <version>9.3.9.v20160517</version>
 +
      <configuration>
 +
        <webAppConfig>
 +
          <contextPath>/test-sample</contextPath>
 +
        </webAppConfig>
 +
        <reload>automatic</reload>
 +
        <scanIntervalSeconds>5</scanIntervalSeconds>
 +
        <systemProperties>
 +
          <systemProperty>
 +
            <name>jetty.port</name>
 +
            <value>8080</value>
 +
          </systemProperty>
 +
        </systemProperties>
 +
        <stopKey />
 +
        <stopPort />
 +
      </configuration>
 +
    </plugin>
 +
  </plugins>
 +
</build></source>
 +
== Customise the web configuration ==
 +
 
 +
Modify the parameters in <code>/src/main/webapp/WEB-INF/web.xml</code> according to the template below.
 +
 
 +
* ''test.sample.webapp'' should be the same as the base package name for your project.
 +
* ''8080'' should match the port number specified in the POM file for Jetty configuration.
 +
 
 +
<source lang="xml"><?xml version="1.0" encoding="UTF-8"?>
 +
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 +
  xmlns="http://java.sun.com/xml/ns/javaee"
 +
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 +
  id="WebApp_ID" version="3.0">
 +
  <display-name>Sample Adaptor</display-name>
 +
  <context-param>
 +
    <description>Base URI for the adaptor.</description>
 +
    <param-name>test.sample.webapp.servlet.baseurl</param-name>
 +
    <param-value>http://localhost:8080</param-value>
 +
  </context-param>
 +
  <listener>
 +
    <description>Listener for ServletContext lifecycle changes</description>
 +
    <listener-class>test.sample.webapp.servlet.ServletListener</listener-class>
 +
  </listener>
 +
  <servlet>
 +
    <servlet-name>JAX-RS Servlet</servlet-name>
 +
    <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
 +
    <init-param>
 +
      <param-name>javax.ws.rs.Application</param-name>
 +
      <param-value>test.sample.webapp.servlet.Application</param-value>
 +
    </init-param>
 +
    <load-on-startup>1</load-on-startup>
 +
  </servlet>
 +
  <servlet-mapping>
 +
    <servlet-name>JAX-RS Servlet</servlet-name>
 +
    <url-pattern>/services/*</url-pattern>
 +
  </servlet-mapping>
 +
</web-app></source>
 +
== Final tips ==
 +
 
 +
If you get the error ''Project configuration is not up-to-date with pom.xml'', simply right click on the eclipse project and select Maven--&gt;Update Project...
  
In the instructions below, we assume an eclipse project named ''SampleAdaptor'', where the java classes are managed under the base package named <code>your.basepackage.name</code>.
+
== Run the adaptor ==
  
; Create a JAVA EE Web Application
+
Once the adaptor is developed, you can run it with <code>mvn clean jetty:run-exploded</code> command.
:- '''File-->New-->Project...'''
+
:- Select ''Web/Dynamic Web Project''
+
:- As project name, specify ''SampleAdaptor''
+
:- On the final step of the wizard, check the '''Generate web.xml...''' option
+
:- Select '''Finish'''
+
; Convert project to Maven
+
:- Right click on the project, and select '''Configure --> Convert to Maven Project'''
+
:- In the window that appears, select ''war'' under '''Packaging'''
+
; Configure the project
+
:- Create a folder '''test''' at the root of the project
+
:- Create the sub-folders '''launches''' & '''resources''' under the new folder '''test'''
+
:- Copy the 3 configuration files from the [[Media:OSLC4JCodeGeneratorconfigurationFileTemplates.zip | Configuration File Templates]] into the corresponding folders:
+
::- ''/SampleAdaptor/pom.xml''
+
::- ''/SampleAdaptor/src/main/webapp/WEB-INF/web.xml''
+
::- ''/SampleAdaptor/src/main/webapp/WEB-INF/jetty.xml''
+
::- If necessary, refresh your Eclipse workspace by right clicking on ''SampleAdaptor -> Refresh''
+
:- If you choose a different name for your project and/or java package, search and replace these values in the project files as instructed under the [[Lyo/creating_OSLC4J_project#Sample_Project | Sample Project]] above.
+
; Activate Project Facet JAX-RS
+
:- Right click the project & Select '''properties'''
+
:- Select the '''Project Facets''' window
+
:- Select '''JAX-RS (REST Web Services)'''
+
:- Click '''OK''' to commit the changes.
+
:- Right click again on the project & Select '''properties'''
+
:- select the new '''JAX-RS''' sub-window under '''Project Facets'''
+
:- Set '''Type:''' to ''Disable Library Configuration''
+
:- Enter '''JAX-RS servlet class name''': ''org.apache.wink.server.internal.servlet.RestServlet''
+
:- Under '''URL mapping patterns''':
+
::- Remove the existing pattern
+
::- Add a new pattern ''/services/*''
+
: '''Note:''' the above two steps (editing the JAX-RS servlet class name and the URL mapping patterns) are no longer available in the Eclipse Mars 4.5 Java EE dialog for the JAX-RS facet. The web.xml file can, of course, be manually edited to make the indicated changes.
+
:- Click '''OK''' to commit the changes.
+
; Further project configuration
+
:- right click the project & select '''Properties'''
+
:- select '''Deployment Assembly'''
+
:- '''Add...'''
+
:- In the new window that appears
+
::- select '''Java Build Path Entries'''
+
::- click '''Next >'''
+
::- select '''Maven Dependencies'''
+
::- click '''Finish'''
+
::- click '''Apply'''
+
::- click '''OK'''
+
; Create a new Run configuration
+
:- Select the menu '''Run-->Run Configurations...'''
+
:- Select '''Maven Build'''
+
:- Create a new Configuration (Right click on '''Maven Build -> New''')
+
:- Enter a '''name''' for the new configuration (such as ''"Launch SampleAdaptor"'')
+
:- Set the '''Base directory''' to ''${workspace_loc:/SampleAdaptor}''
+
:- Set '''Goal''' as ''jetty:run-exploded''
+
:- Switch to tab '''JRE'''
+
::- Set '''Runtime JRE''' to ''Workspace default JRE...''
+
:- Switch to tab '''Source'''
+
::- Click '''Add...'''
+
::- In the new window, select '''Project''' and click '''OK'''
+
:::- Check the ''SampleAdaptor'' project
+
:::- Check the '''add required projects of selected projects''' option
+
:::- Click '''OK'''
+
:- Switch to Tab '''Common'''
+
::- Select '''Shared file'''
+
::- Click '''Browse...'''
+
::- In the window that appears, select the recently created folder ''test/launches'' under the ''SampleAdaptor'' project
+
::- click '''OK'''
+
:- Click '''Apply'''
+
:- Clock '''Close'''
+

Revision as of 04:18, 26 April 2017

Eclipse Setup

Make sure your environment is setup for OSLC4J development as instructed on General Setup for OSLC4J development

Create an OSLC4J project

The steps below guide you through the necessary steps of creating an Eclipse project with the necessary configurations to develop any OSLC4J adaptor.

In the instructions below, we assume the following parameters:

  • Eclipse Project Name: test-sample-webapp
  • Base Package Name for Java Classes: test.sample.webapp

We will here only create the code skeleton. The Toolchain Modelling and Code Generation Workshop can then be used to generate the necessary code to become a fully functional adaptor.

Creation of the skeleton consists of 2 steps:

  1. creating a Maven project from an archetype
  2. customising the generated project with the Lyo-specific configuration

Creating a Maven project from an archetype

To create a Maven project from an archetype via Eclipse

  1. select File > New >Other
  2. then select Maven Project under Maven group.
  3. Leave the Create a simple project checkbox unchecked.
  4. Uncheck the Use default Workspace location option and point it to the project root
  5. Press Next
CreateMavenAdaptorProject Step1.png

Next, select the maven-archetype-webapp archetype:

CreateMavenAdaptorProject Step2.png

Next, Fill in the Group Id, Artefact Id, and the Package Base.

  • The Package Base value (test.sample.webapp on this page) will be used as a base package for your adaptor code.
CreateMavenAdaptorProject Step3.png

You should now have the project in Eclipse and the following folder structure:

CreateMavenAdaptorProject CodeStructure.png

Customise the project POM file

We now need to modify the project pom.xml file.

General POM changes

We need to make sure our project uses UTF-8 and JDK 1.8. We will also use properties to define a common version for Lyo Core and Lyo Server packages:

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
  <version.lyo.core>2.1.2</version.lyo.core>
  <version.lyo.server>2.1.0</version.lyo.server>
</properties>

We require Java EE 6 or higher and JSTL:

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.1.0</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>jstl</artifactId>
  <version>1.2</version>
</dependency>

Lyo package dependencies

an OSLC4J project will use Lyo dependencies that we need to declare. Before we can do that, we need to add the Lyo repository:

  <repositories>
    <repository>
      <id>lyo-releases</id>
      <name>lyo-releases repository</name>
      <url>https://repo.eclipse.org/content/repositories/lyo-releases/</url>
    </repository>
  </repositories>

Now were are ready to add the dependencies.

Lyo uses SLF4J for logging, leaving the choice of the actual logging library to use. We will use the simplest option:

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.7.21</version>
  <scope>runtime</scope>
</dependency>

Lyo dependencies need:

<dependency>
  <groupId>org.eclipse.lyo.oslc4j.core</groupId>
  <artifactId>oslc4j-core</artifactId>
  <version>${version.lyo.core}</version>
  <exclusions>
    <exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.eclipse.lyo.oslc4j.core</groupId>
  <artifactId>oslc4j-jena-provider</artifactId>
  <version>${version.lyo.core}</version>
  <exclusions>
    <exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.eclipse.lyo.oslc4j.core</groupId>
  <artifactId>oslc4j-wink</artifactId>
  <version>${version.lyo.core}</version>
</dependency>
<dependency>
  <groupId>org.eclipse.lyo.oslc4j.core</groupId>
  <artifactId>oslc4j-json4j-provider</artifactId>
  <version>${version.lyo.core}</version>
</dependency>
Exclusions are due to the Bug 513477

Finally, your adaptor might need to includes the experimental support for OAuth:

<dependency>
  <groupId>org.eclipse.lyo.server</groupId>
  <artifactId>oauth-core</artifactId>
  <version>${version.lyo.server}</version>
</dependency>
<dependency>
  <groupId>org.eclipse.lyo.server</groupId>
  <artifactId>oauth-consumer-store</artifactId>
  <version>${version.lyo.server}</version>
  <exclusions>
    <exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.eclipse.lyo.server</groupId>
  <artifactId>oauth-webapp</artifactId>
  <version>${version.lyo.server}</version>
  <type>war</type>
</dependency>
OAuth is enabled by default. If you want to disable it, open the generated Application class and do the following changes:
  • comment out line RESOURCE_CLASSES.add(Class.forName("org.eclipse.lyo.server.oauth.webapp.services.ConsumersService"));
  • comment out line RESOURCE_CLASSES.add(Class.forName("org.eclipse.lyo.server.oauth.webapp.services.OAuthService"));
  • change catch (ClassNotFoundException e) to catch (Exception e)

If you use OAuth or consume any resources in your Adaptor Interface, an OSLC client dependency is needed:

<dependency>
  <groupId>org.eclipse.lyo.clients</groupId>
  <artifactId>oslc-java-client</artifactId>
  <version>${version.lyo.core}</version>
  <exclusions>
    <exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>jcl-over-slf4j</artifactId>
    </exclusion>
  </exclusions>
</dependency>

Embedded Jetty server for quick debugging

Finally, you should use an embedded servlet container during the debugging to simplify the development process. Jetty configuration looks the following, where the port number (8080 below) can be adjusted as appropriate.

<build>
  <plugins>
    <plugin>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-maven-plugin</artifactId>
      <version>9.3.9.v20160517</version>
      <configuration>
        <webAppConfig>
          <contextPath>/test-sample</contextPath>
        </webAppConfig>
        <reload>automatic</reload>
        <scanIntervalSeconds>5</scanIntervalSeconds>
        <systemProperties>
          <systemProperty>
            <name>jetty.port</name>
            <value>8080</value>
          </systemProperty>
        </systemProperties>
        <stopKey />
        <stopPort />
      </configuration>
    </plugin>
  </plugins>
</build>

Customise the web configuration

Modify the parameters in /src/main/webapp/WEB-INF/web.xml according to the template below.

  • test.sample.webapp should be the same as the base package name for your project.
  • 8080 should match the port number specified in the POM file for Jetty configuration.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://java.sun.com/xml/ns/javaee"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  id="WebApp_ID" version="3.0">
  <display-name>Sample Adaptor</display-name>
  <context-param>
    <description>Base URI for the adaptor.</description>
    <param-name>test.sample.webapp.servlet.baseurl</param-name>
    <param-value>http://localhost:8080</param-value>
  </context-param>
  <listener>
    <description>Listener for ServletContext lifecycle changes</description>
    <listener-class>test.sample.webapp.servlet.ServletListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
    <init-param>
      <param-name>javax.ws.rs.Application</param-name>
      <param-value>test.sample.webapp.servlet.Application</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
</web-app>

Final tips

If you get the error Project configuration is not up-to-date with pom.xml, simply right click on the eclipse project and select Maven-->Update Project...

Run the adaptor

Once the adaptor is developed, you can run it with mvn clean jetty:run-exploded command.

Back to the top