Integrating Swagger 2.0 with Glassfish 4.1 OSGi REST project - osgi

Do I need to specifically include the JAX-RS and HttpServlet jars to integrate Swagger 2.0 into my JAX-RS project?
I am trying to present my RESTful services developed in the following specifications:
Java
NetBeans IDE 8.0.2 [Maven]
OSGi 4.2
The project exchanges information in JSON format
Glassfish 4.1
JAX-RS 2.0
Jersey 2.0
The project deploys successfully onto Glassfish, but when any of the REST services are called, it throws an Error 404. The server log complains about class loading errors, specifically javax.ws.rs.* (despite javax.ws.rs-api being provided), and produces
java.lang.NoClassDefFoundError: javax/ws/rs/core/Application
pom.xml -- Maven Bundle Plugin
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.4</version>
<extensions>true</extensions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>ejb</supportedProjectType>
<supportedProjectType>war</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
<supportedProjectType>jar</supportedProjectType>
</supportedProjectTypes>
<instructions>
<!-- Specify elements to add to MANIFEST.MF -->
<Web-ContextPath>/sample</Web-ContextPath>
<!-- By default, nothing is exported -->
<!--<Export-Package>!*.impl.*, *</Export-Package>-->
<Import-Package>
!com.sun*;resolution:=optional,
!javassist*;resolution:=optional,
!groovy*;resolution:=optional,
!javax.microedition*;resolution:=optional,
!org.apache*;resolution:=optional,
!org.codehaus*;resolution:=optional,
!nu.xom;resolution:=optional,
!org*;resolution:=optional,*
</Import-Package>
<Bundle-ClassPath>.,WEB-INF/classes,WEB-INF/lib/slf4j-api-1.7.12.jar,WEB-INF/lib/slf4j-jdk14-1.7.12.jar,{maven-dependencies}</Bundle-ClassPath>
<Embed-Dependency>
annotations,asm-all-repackaged,cglib,
aopalliance-repackaged,commons-lang3,commons-vfs2,
dom4j,gson,guava,
hk2-api,hk2-locator,hk2-utils,
jackson-core,jackson-annotations,jackson-databind,
jackson-dataformat-yaml,jackson-dataformat-xml,
jackson-datatype-joda,jackson-jaxrs-base,
jackson-jaxrs-json-provider,
jackson-module-jaxb-annotations,
javaee-web-api,
javassist,
javax.ws.rs-api,
javax.annotation-api,javax.inject,javax.json-api,
javax.servlet-api,
jaxen,jaxb-api,
jersey-client,jersey-common,jersey-server,
jersey-container-servlet-core,
jersey-media-multipart,
joda-convert,joda-time,jsch,jsr311-api,jzlib,
logback-classic,logback-core,
mongo-java-driver,maven,mimepull,
org.apache.felix.scr.annotations,
org.apache.servicemix.bundles.commons-httpclient,
org.osgi.compendium,org.osgi.core,
osgi-cdi-api,osgi-resource-locator,
pull-parser,reflections,
slf4j-api,slf4j-jdk14,
snakeyaml,stax2-api,
swagger-annotations,swagger-core,swagger-jaxrs,
swagger-jersey2-jaxrs,swagger-models,
validation-api;
scope=compile|runtime;
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
<execution>
<id>bundle-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
Work done so far:
Updated Glassfish 4.1 to include Jersey 2 & JAX-RS 2
All Jersey-Glassfish dependencies marked as "provided"
Resolved duplicate dependencies

Make sure that the javax.ws.rs.* packages are provided by the system bundle. You can connect to the OSGi Module Management Subsystem of glassfish using the Felix Gogo Remote Shell and query the registry using the built-in commands.

Related

Maven Hibernate bytecode enhancement not working

I'm trying to add Bytecode Enhancement to my Maven Spring project created with Spring Initializr, so that I can use lazyloading in a #Formula, whoever, it's not working
I've added the plugin to the build > plugins section of my pom.xml:
<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>${hibernate.version}</version>
<executions>
<execution>
<configuration>
<failOnError>true</failOnError>
<enableLazyInitialization>true</enableLazyInitialization>
<enableDirtyTracking>false</enableDirtyTracking>
<enableAssociationManagement>false</enableAssociationManagement>
<enableExtendedEnhancement>false</enableExtendedEnhancement>
</configuration>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
If I run the goal manually, I get the following warning:
[WARNING] Skipping Hibernate bytecode enhancement plugin execution since no feature is enabled
I saw only one other mention of this problem on the internet, and they said that it was probably a configuration problem with Maven, because the plugin is not able to read those properties on the .xml, but what could I do? This is basically a fresh Spring Initializr project.

While creating a Maven project using archetype13, I have faced Sling IDE issues for core and test pom.xml

while creating a maven project using archetype13, I have faced Sling IDE issues as below for core and test pom.xml
This is the error that I get:
"Missing m2e incremental build support for generating the bundle manifest, component descriptions and metatype resources.
Please use the provided Quick Fixes on this issue to resolve this. pom.xml /AEMEditable.core line 1 Bundle Project Not Supporting M2E"
Note: Figured out how to solve this.
We need to manually modify the pom.xml for core and test, under maven-bundle plugin.
For both core and test pom.xml add the following code :
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<!-- Configure extra execution of 'manifest' in process-classes phase
to make sure SCR metadata is generated before unit test runs -->
<execution>
<id>scr-metadata</id>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<supportIncrementalBuild>true</supportIncrementalBuild>
</configuration>
</execution>
</executions>
<configuration>
<instructions>
<!-- Import any version of javax.inject, to allow running on multiple versions of AEM -->
<Import-Package>javax.inject;version=0.0.0,*</Import-Package>
<Sling-Model-Packages>
AEMEditable.core
</Sling-Model-Packages>
<!-- Enable processing of OSGI DS component annotations -->
<_dsannotations>*</_dsannotations>
<!-- Enable processing of OSGI metatype annotations -->
<_metatypeannotations>*</_metatypeannotations>
</instructions>
<exportScr>true</exportScr>
</configuration>
</plugin>
Check image:
Once this is done, select the whole project in eclipse, right click, Click on Maven --> Update Project

Is it possible to get the maven install plugin to deploy the ejb client jar?

After years of working with Spring, I'm working on a Java EE 7 application with EJB 3.2 and Maven. One thing I would like is to deploy the EJB Jars separately from the web application so I can develop independently. Including the EJB Jars in the WAR causes the app server to redefine the EJBs in the context of the WAR, which I don't want to happen.
The prescribed method is to have maven create a client jar with this directive:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<ejbVersion>3.2</ejbVersion>
<generateClient>true</generateClient>
<clientExcludes>
<clientExclude>**/*Impl.class</clientExclude>
</clientExcludes>
</configuration>
</plugin>
I'm excluding any Impls from the Client JAR.
The issue I'm having is that maven isn't installing the client jar during the install phase.
I can install it manually by doing this:
mvn install:install-file -Dfile=foo-1.0-client.jar -DgroupId=com.awesome -DartifactId=foo -Dversion=1.0 -Dpackaging=jar -Dclassifier=client
I fiddled around a lot and came up with this
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<ejbVersion>3.2</ejbVersion>
<generateClient>true</generateClient>
<clientExcludes>
<clientExclude>**/*Impl.class</clientExclude>
</clientExcludes>
</configuration>
<executions>
<execution>
<id>package</id>
<phase>package</phase>
<goals>
<goal>ejb</goal>
</goals>
</execution>
<execution>
<id>install</id>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
However, this isn't proper. This installs the client as a new artifact, not as the same artifact with classifier client. When you include the client in another application, you are supposed to use ejb-client. This looks in your folder that contains the normal artifact, foo-1.0.jar, and looks for something with classifier client.
<dependency>
<groupId>com.awesome</groupId>
<artifactId>foo</artifactId>
<version>${com.awesome.version}</version>
<type>ejb-client</type>
</dependency>
Stumped here, any ideas?

Deploy a web-application on Websphere 8.5 using maven 3

I´m trying to make a Maven Project from an existing web application using JSF. The Project
should be deployed on Web Sphere 8.5.
Since i'm new to Web Sphere, don´t know how to build the "ear" Module, in order to be deployable on Web Sphere 8.5.
Does anyone know, where i can find further Information about deploying a web application on Web Sphere 8.5 using Maven 3.0.3?
Thanking you in anticipation,
Mosen
I've never worked with WebSphere Application Server 8.5; but in the days I was playing with IBM WAS 6.1 the WAS6 Maven plugin worked pretty well (it seems it works with WAS7 too). Here's a POM fragment from the plugin site that allows automatic EAR deployment:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>was6-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>installApp</goal>
</goals>
</execution>
</executions>
<configuration>
<wasHome>${was61home}</wasHome>
<host>deploymentmanager.your.domain</host>
<username>admin</username>
<password>adminpassword</password>
<targetCluster>nameOfCluster</targetCluster>
<profileName>Dmgr01</profileName>
<conntype>SOAP</conntype>
<port>8879</port>
<verbose>true</verbose>
<updateExisting>false</updateExisting>
</configuration>
</plugin>
That plugin is for deployment and other administrative task, for EAR generation you can use the Maven EAR Plugin as described in 20InchMovement answer.
Hope this could helps:
<plugin>
<groupId>com.orctom.mojo</groupId>
<artifactId>was-maven-plugin</artifactId>
<version>1.0.8</version>
<executions>
<execution>
<id>deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<wasHome>${env.WAS_HOME}</wasHome>
<applicationName>${project.build.finalName}</applicationName>
<host>${local or remote address}</host>
<server>server01</server>
<node>node01</node>
<virtualHost>default_host</virtualHost>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
From https://github.com/orctom/was-maven-plugin
in order to package an *.ear, you don't need Websphere.
This can be accomplished with maven itself.
pom.xml:
<project>
...
<artifactId>YourApp</
<packaging>ear</packaging>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<modules>
<jarModule>
<groupId>${project.parent.groupId}</groupId>
<artifactId>configurationApp</artifactId>
</jarModule>
<ejbModule>
<groupId>${project.parent.groupId}</groupId>
<artifactId>AnEjbModule</artifactId>
</ejbModule>
</modules>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
...
</project>
Then you add your dependencies.
On command line go to your project and run mvn package.
Because of the package defined in you pom.xml, the ear will be created and can be found in the YourApp/target directory.
On the websphere admin console you can simply install the ear.
After login, goto:
Applications->Websphere enterprise applications and install a new application.
Select your YourApp.ear and go for easiness through the fast path to install the app.
The port to check is probably
yourServerName:9080/YourApp.
Good luck.
See http://code.google.com/p/websphere-maven-plugin/
Websphere Maven Plugin provides goals to:
deploy ear on websphere 7
start application
stop application
uninstall
require websphere application client.

How to integrate jrebel in arquillian tests on remote jboss testing?

Testing java persistence, want to integrate jrebel on arquillian tests. I've read something about an arquillian jrebel extension, but could not configure it well (maven dependency error).
Right now I'm just running remotely Jboss with jrebel plugin, on pom.xml:
<plugin>
<groupId>org.zeroturnaround</groupId>
<artifactId>jrebel-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-rebel-xml</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
Is the above enough?
What maven plugin does is that it generates rebel.xml configuration file. It is required to map the resources outside of the deployed application. The JVM itself should be started with a -javaagent argument (see the manual). For Arquillian, there's a community contributed extension, but I'm not sure how it actually works.

Resources