jersey archetype sun or glassfish - maven

I´m new with Jersey and I have problems with the installation. Specially with the error:
Can't resolve Archetype
org.glassfish.jersey.archetypes:jersey-heroku-webapp:2.26
I already looked for solutions:
adding a remote catalog
adding a new Maven Archetype locally
proxy setting are working (I can access a web page using my internal browser)
Now, I noticed that when creating a new Maven project and selecting the archetype it appears:
com.sun.jersey.archetypes
Can I use that to run jersey? or Is only with
org.glassfish.jersey.archetypes
any suggestions?

com.sun.jersey.archetypes <- Jersey 1.x (see docs)
org.glassfish.jersey.archetypes <- Jersey 2.x (see docs)
For new projects, use 2.x

Related

Deploy Spring Boot project to WebSphere 8.5.5

I'm trying to deploy my spring boot project (made by spring initializr) with maven (but same issue with gradle) on WebSphere Application Server 8.5.5 but it seems impossible to me.
Every-time I try to add to server from "Add and Remove" it says "There are no resources that can be added or removed from the server".
So I tried changing Dynamic Web Module on Project properties --> project facets but nothing changed.
Is it possible to deploy on WAS 8.5.5?
I found a similar reported issue here: Cannot 'Add and Remove' Maven Project with Websphere 7 on RAD 8.5.
I completely removed my project from RAD. I then extracted zip file from Spring Initializr to create a Maven project. I used "mvnw eclipse:eclipse" command and it successfully created build. I imported that as a general project to RAD.
I then clicked on project. Clicked on properties. Clicked on project facets. None were available, but it prompted me to create them and I did. From there, I selected Dynamic Web Module facet (and also JAX-RS, but I'm not sure if you'll care about that one). I clicked apply and close.
After this, I was able to add and remove resource to Websphere server. I don't know if this is preferred steps or not. I am learning, just as you are. But, it appeared to work.
I specified Java 8 Jar in Spring Initializr for packaging. Maven version is 3.8.4. Spring Boot 2.6.5 (it was pre-selected for me). I am using RAD 9.7 and Websphere server that is stood up in IDE is version 8.5.5.
To deploy spring boot to WebSphere 9 you would want to choose War packaging and Java 8. The zip file from the spring initializr includes a Help.md file with links to helpful documentation. After you extract the zip file, use File -> Import existing maven project into a new workspace.

What is the archetype to use to build a SpringBoot project?

For years, I've used Spring Initializr (at https://start.spring.io/) to create the initial SpringBoot application and then modify it to create the app. This works fine.
Is there a maven archetype I can use to create a SpringBoot app? Or is the Spring Initializr the only way to do this.
Searching I found this:
What archetype to choose for a simple java project
Which shows the command:
mvn archetype:generate -Dfilter=org.apache.maven.archetypes:
Which gives me a list of 14 items to choose from. None of them mention SpringBoot.
The closest match is org.apache.maven.archetypes:maven-archetype-webapp, so I tried it and it created a WebApp (*.war) which is not what I'm looking for.
The aim of the Maven archetype is for generating a project skeleton. The Spring Initialiser also does the same but I think you should find it more user friendly to use when compared to executing a maven archetype command.
If you insist to use maven archetype , you can simply search Github to see if there are people share their archetypes (search result at here)
If your aim is just to use command to generate a spring-boot project skeleton , Spring Initializr actually provide an HTTP API to do it.
Also you can checkout JHipster, which is another tool to generate a spring-boot project skeleton.
You could also use Spring Boot CLI to scaffold new Spring Boot projects:
spring init --dependencies=web,data-jpa my-new-project
It works just as Spring Initializr, but on the command line.
See section 2.4 "Initialize a New Project" on Spring Boot CLI documentation here: https://docs.spring.io/spring-boot/docs/current/reference/html/cli.html#cli.using-the-cli.initialize-new-project

Spring Boot: change from Java Servlet 3.1 to 3.0

In Eclipse (STS) I created a project as follows:
File -> New -> Spring Starter Project
The settings are (among others):
Type: Maven Project
Packaging: War
Java Version: 1.8
Language: Java
Boot Version: 1.3.0
Dependencies: Web
In the project facets it leads to Dynamic Web Module = 3.1, however I need 3.0.
Manually setting it to 3.0 leads to "Cannot change version of project facet Dynamic Web Module to 3.0".
Besides this error message I am sure this is not the right way to change it because the project will be shared to others.
I guess there is a maven way.
Maybe the solution is somewhere here: http://docs.spring.io/spring-boot/docs/1.3.0.RELEASE/maven-plugin/plugin-info.html.
Unfortunately Spring Boot and Maven are not my special topics (yet).
Not the correct way but, the easiest way to fix that issue is 'Delete' that error from the 'Problems' tab. It will be removed and your code will be compiled on STS. But, it may come back at some point then just delete that error again.

how to create spring template project in sts-3.6.3?

please suggest if is there any other solution to do scaffolding of an app in STS.
In many examples/tutorials about creating web services using Spring MVC framework are using Spring MVC project template. I can't find it in my project tempaltes list. Am i missing some plugin installed?
The best way to create a new Rest service Spring app in STS 3.6.3 and beyond is to select the "Import Spring Getting Started Content". This allows you to get the guides from http://spring.io/guides directly into your workspace. If you look for "Rest Service" in the list of available guides, the wizard will download the initial and the completed version of this guide, showing you how to write a Rest service using the latest Spring versions. The completed version of the project could also be used for just creating a new Spring project and continue to do development from there.

Example using Jersey (REST resource), OSGi (Apache Felix), and Maven (build and deploy)?

I seem to be really struggling here. What I want to do (in this order) is:
1) Build a RESTful resource using a Jersey application and resource w/annotations (this is not the issue).
2) Package, install, and start that bundle into the Felix OSGi container, as an HTTP service, including dependencies.
3) Package, install, and start a WAR in the OSGi container that may incorporate #2 as a dependency.
And I would like to be able to do all of this using Maven.
I cannot seem to find a working example of even the individual steps, especially involving Maven, that work let alone the combination of those steps. I have tried cobbling together various q&a from across the web with varying levels of success but not an end-to-end working example yet.
Any pointers would be appreciated...
I do not have an example for Jersey but I have a tutorial for CXF with Apache Karaf (which uses Felix). It shows how to create a Rest service and build it with maven. Using Apache Karaf you can then deploy the bundle directly from the maven repo. Moving this to Jersey probably just means to exchange the lib and use another blueprint config to initialize the rest service.
Apache Karaf also allows to deploy wars and wabs but I have not yet tested them.
Apache Stanbol does most or all of this (not sure if the war packaging is included out of the box) to implement its RESTful services.
You'll have to dig through its codebase but searching for Jax-RS annotations in there should point you to the right places.
I also am really struggling with exactly what you are attempting to do. So far, I seem to be really close but alas not quite there, here's what I've been doing:
creating a War with Maven that defines my Jersey Resource's
bundling it with maven bundle plugin ( see section Adding OSGi metadata to existing projects without changing the packaging type ). Which allows me to run the restlets in Tomcat and test.
define a target in Eclipse that includes resources from my locally defined p2 site which I create with the p2-maven-plugin plugin. In this way I can gather up any of the dependencies from the WAR project into a p2 site, which I can deploy to an Eclipse defined target
Where I am stuck is trying to register the Jersey Resource's as services, for which I've tried:
using the JAX-RS OSGI connector, for which I eventually gave up on because it uses glassfish jersey which seems to export a version 2 API of Jersey when Jersey hasn't even defined a version 2 API yet. This caused package resolution problems when I wanted to use version 1.17 of Jersey libs.
registering the Resources using a Whiteboard a la Apache Felix HTTP Service, my current approach which doesn't seem to work yet.
And, finally, if the preceding doesn't work I'll try Amdatu
Another route I might try is from the Jersey project OSGI chapter
I tried this combination and made it up and running -
1- Modularity Specification-->OSGi specification
2- OSGi implementation-->Apache Felix 4.4.0
3- OSGi Runtime-->Apache Karaf 3.0.3
4- Software Architecture Specification of REST – JAX-RS
5- JAX-RX implementation-->Apache CXF – 2.7.5
You can refer this nice tutorial - http://java.dzone.com/articles/building-cxf-rest-service-osgi
Now, I am also planning to move to Jersey from CXF as the Jersey is the light wait reference implementation of JAX-RS. Now I am planning to use Jersey with Apache Felix/Apache Karaf. You can install Jersey in Karaf and deploy your Jersey Rest Web Services as Bundle. You can refer this tutorial - https://vzurczak.wordpress.com/2014/09/30/web-applications-with-osgi-working-with-jersey/
Here's a good example on github : https://github.com/ddragosd/jax-rs-on-karaf

Resources