To ease developing my endpoints returning JSON, I want to enable prettyprinting.
The solution I'm tyring to implement is adding a filter that injects an ObjectWriterModifier enabling the default pretty printer, if the query string is ?pretty=1.
Deployment fails as it cannot find the class com/fasterxml/jackson/jaxrs/cfg/ObjectWriterModifier
which is contained in jackson-jaxrs-base-2.7.4.jar under modules/system/layer/base/com/fasterxml/jackson/core/jaxrs/jackson-jaxrs-json-provider of my WildFly 10 installation.
In my build.gradle I do specify the dependicy as provided:
dependencies {
providedCompile 'javax:javaee-api:7.0'
providedCompile 'com.fasterxml.jackson.core:jackson-core:2.7.4'
providedCompile 'com.fasterxml.jackson.core:jackson-annotations:2.7.4'
providedCompile 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.7.4'
}
Here is module.xml for jackson-jaxrs-json-provider
<module xmlns="urn:jboss:module:1.3" name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider">
<resources>
<resource-root path="jackson-jaxrs-json-provider-2.7.4.jar"/>
<resource-root path="jackson-jaxrs-base-2.7.4.jar"/>
<resource-root path="jackson-module-jaxb-annotations-2.7.4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.ws.rs.api"/>
<module name="javax.xml.bind.api"/>
<module name="com.fasterxml.jackson.core.jackson-annotations"/>
<module name="com.fasterxml.jackson.core.jackson-core"/>
<module name="com.fasterxml.jackson.core.jackson-databind"/>
</dependencies>
</module>
I don't see how WildFly can't find a class that's inside one of the jars it provides
Have a look at the class loading documentation. You may need to add a module dependency as all modules aren't just automatically added as a dependency to deployments.
Related
I am using log4j 2.16 for my EJBs. Im meaning to add the log4j-core (and log4j-api if necessarily ) as module in jBoss eap 7 but I keep getting the ModuleNotFoundException exception.
here is my configurations :
src/main/ressource/META-INF/jboss-deployement-structure.xml
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.lg.log4j2"/>
</dependencies>
<exclude-subsystems>
<subsystem name="logging"/>
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
pom.xml
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.16.0</version>
<scope>provided</scope>
</dependency>
jboss-eap-7.0 - 22\modules\system\layers\base\org\lg\main
<module xmlns="urn:jboss:module:1.1" name="org.lg.log4j2">
<resources>
<resource-root path="log4j-api.jar"/>
<resource-root path="log4j-core.jar"/>
</resources>
</module>
the two jar exist in the current folder.
EJBXX.jar.failed
WFLYSRV0179: Failed to load module: deployment.EJBXX.jar:main
Caused by: org.jboss.modules.ModuleNotFoundException: org.lg.log4j2:main\"}}"
I am not sure about my solution so please correct me if there is another way to achieve it.
N.B: I spot this error in my jBoss console :
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Your module is in the wrong directory. It needs to be in org/lg/log4j2/main. You’re also likely missing some module dependencies too.
I have been at this all day and not getting it to work after trying so many combinations. At the end of the day, I am looking for an explicit list of steps to get JSON logging from Karaf. I have even gone through the Maven Karaf plugin source code trying to sort this out, though perhaps I didn't look far enough.
I am using Karaf 4.2.6. I am attempting to build a Karaf deployment using the karaf-maven-plugin, version 4.2.6.
If I change my layout.type for various appenders to JsonLayout, I get a stacktrace saying it can't load the JSON layout because I am missing a class. java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ser/FilterProvider.
I looked at the jar org.ops4j.pax.logging/pax-logging-log4j2/1.10.2 and found I needed 3 Jackson jars, Core v2.8.7, Annotations v2.8.0, and Databind v2.8.7.
I have been trying to get these files in etc/startup.properties with either the start level of 5 or the start level of 8 so that they are ready for org.ops4j.pax.logging/pax-logging-log4j2/1.10.2 when it starts. I made sure they were in the system folder in the correct place. Most of the time, if I did get them into etc/startup.properties, they had a start level of 30. I placed them in a feature with the correct start levels, but they were either started well after whatever used startup.properties or just never showed up. I tried many possibly combinations, startupBundles, startupFeatures, bootFeatures, but nothing got it in startup.properties. I could not figure out how the contents of startup.properties got generated. Sometimes the features I wanted for my application wouldn't even start because something about the configuration got blocked on setting up the logging if I just placed references to those jars in startup.properties, for example
mvn\:com.fasterxml.jackson.core/jackson-core/2.8.7 = 5
Below is my pom.xml with somethings from previous attempts commented out:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<properties>
<my_version>0.0.0</my_version>
<myapp_common_version>0.0.0</myapp_common_version>
</properties>
<groupId>com.me.myapp</groupId>
<artifactId>myapp-karaf</artifactId>
<version>${my_version}</version>
<packaging>karaf-assembly</packaging>
<name>myapp-karaf</name>
<description>myapp-karaf details</description>
<repositories>
<!-- Apache ServiceMix repository (for region) -->
<repository>
<id>apache.servicemix.m2</id>
<name>Apache ServiceMix M2 repository</name>
<url>http://svn.apache.org/repos/asf/servicemix/m2-repo</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- OPS4J SNAPSHOT repository -->
<repository>
<id>ops4j.sonatype.snapshots.deploy</id>
<name>OPS4J snapshot repository</name>
<url>https://oss.sonatype.org/content/repositories/ops4j-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<!-- Apache SNAPSHOT -->
<repository>
<id>apache.snapshots.deploy</id>
<name>Apache snapshot repository</name>
<url>https://repository.apache.org/content/groups/snapshots-group</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>framework</artifactId>
<version>4.2.6</version>
<type>kar</type>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>standard</artifactId>
<version>4.2.6</version>
<classifier>features</classifier>
<type>xml</type>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>spring</artifactId>
<version>4.2.6</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>enterprise</artifactId>
<version>4.2.6</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.me.myapp</groupId>
<artifactId>myapp-common-feature</artifactId>
<version>${myapp_common_version}</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.me.myapp</groupId>
<artifactId>myapp-feature</artifactId>
<!-- Annoyingly this cannot come from an environment variable -->
<version>${my_version}</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${env.MYAPP_SOURCE_HOME}/myapp-common/server/karaf/assembly</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>src/main/filtered-resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>4.2.6</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>process-resources</id>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<configuration>
<startupBundles> <!--
<bundle>mvn:com.fasterxml.jackson.core/jackson-annotations/2.8.0</bundle>
<bundle>mvn:com.fasterxml.jackson.core/jackson-core/2.8.7</bundle>
<bundle>mvn:com.fasterxml.jackson.core/jackson-databind/2.8.7</bundle> -->
</startupBundles>
<installedFeatures>
</installedFeatures>
<startupFeatures>
<feature>com.me.myapp/${my_version}</feature>
</startupFeatures>
<bootFeatures>
<feature>com.me.myapp.logging.provider/${myapp_common_version}</feature>
<!-- standard distribution -->
<!-- <feature>standard</feature> -->
<!-- minimal distribution -->
<!--<feature>minimal</feature>-->
<feature>jaas</feature>
<feature>shell</feature>
<feature>ssh</feature>
<feature>management</feature>
<feature>bundle</feature>
<feature>config</feature>
<feature>deployer</feature>
<feature>diagnostic</feature>
<feature>instance</feature>
<feature>kar</feature>
<feature>wrap</feature>
<feature>log</feature>
<feature>package</feature>
<feature>service</feature>
<feature>system</feature>
</bootFeatures>
<javase>1.8</javase>
</configuration>
</plugin>
</plugins>
</build>
</project>
com.me.myapp.logging.provider contains the Jackson jars with the proper start level.
I am running my containers in Kubernetes and want standard log collection in Kubernetes to work. I am using using an extra plugin on the logs collector to at least separate things somewhat into a JSON format, but it is error prone and I'd rather just start with JSON formatted logs rather than processing later downstream so I can separate components of the log, such as person who did the operation, at the time of logging.
I have searched on Stack Overflow, have Googled, and found hints, but no explicit steps that lead to a solution. I realize there is not an explicit listing of files here, but, as I said, I went through many combinations. Any help would be MUCH appreciated. I will also post on the Karaf user group.
OK, after several days, I figured out everything that needed to be done. Thank you #GrzegorzGrzybek for the help.
I needed the following lines
mvn\:org.ops4j.pax.logging/pax-logging-log4j2-extra/1.11.4 = 8
mvn\:com.fasterxml.jackson.core/jackson-core/2.9.10 = 8
mvn\:com.fasterxml.jackson.core/jackson-annotations/2.9.10 = 8
mvn\:com.fasterxml.jackson.core/jackson-databind/2.9.10 = 8
added to my etc/startup.properties. If I just edited the file to add them, and made sure I had the files in the system repository, it would not work. No idea, some entry was not being made somewhere else in the etc configs so either the container wouldn't start, or some feature sets were being started up before the wrap handler was installed, so the whole container would grind to a halt.
I tried lots of combinations, but finally found how to get things into etc/startup.properties. I placed the bundles I wanted into their own feature with the start level I wanted them to have.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.3.0" name="myapp-common-container-feature">
<feature name="com.me.myapp.logging.provider" version="0.12.0" description="MyApp Logging Provider">
<bundle start-level="8">mvn:com.fasterxml.jackson.core/jackson-annotations/2.9.10</bundle>
<bundle start-level="8">mvn:com.fasterxml.jackson.core/jackson-core/2.9.10</bundle>
<bundle start-level="8">mvn:com.fasterxml.jackson.core/jackson-databind/2.9.10</bundle>
<bundle start-level="8">mvn:org.ops4j.pax.logging/pax-logging-log4j2-extra/1.11.4</bundle>
</feature>
</features>
Notice the start-level attribute.
Then, in my assembly POM, I put the following dependency:
<dependency>
<groupId>com.me.myapp</groupId>
<artifactId>myapp-common-container-feature</artifactId>
<version>0.12.0</version>
<classifier>features</classifier>
<type>xml</type>
<scope>compile</scope>
</dependency>
The important line here is <scope>compile</scope>. Features in the compile scope will be placed in startup.properties if placed in <startupFeatures /> in the configuration for the Karaf Maven Plugin.
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<configuration>
<startupFeatures>
<feature>com.me.myapp.logging.provider/0.12.0</feature>
</startupFeatures>
Now the container starts up with JSON logging.
On my side, I followed Keith's answer but this was not sufficient as I had already another older version of Jackson in the OSGI container.
Here is what I did:
Added the log4j2 extra with the three Jackson libs (version 1.11.13 of Pax-Logging + jackson version 2.12.4) in the startup.properties:
mvn\:com.fasterxml.jackson.core/jackson-annotations/2.12.4 = 6
mvn\:com.fasterxml.jackson.core/jackson-core/2.12.4 = 6
mvn\:com.fasterxml.jackson.core/jackson-databind/2.12.4 = 6
mvn\:org.ops4j.pax.logging/pax-logging-log4j2-extra/1.11.13 = 6
mvn\:org.ops4j.pax.logging/pax-logging-api/1.11.13 = 8
mvn\:org.ops4j.pax.logging/pax-logging-log4j2/1.11.13 = 8
And in the overrides.properties:
mvn:com.fasterxml.jackson.core/jackson-core/2.12.4;range="[2,3)"
mvn:com.fasterxml.jackson.core/jackson-databind/2.12.4;range="[2,3)"
mvn:com.fasterxml.jackson.core/jackson-annotations/2.12.4;range="[2,3)"
and only after this I was able to see my Json log properly formatted (with JsonLayout deprecated way).
I also tried the new way by trying to deploy bundle log4j-layout-template-json but it seems this lib is wrongly released (host fragment is referring to itself).
I put these jars in system repository, installed using wraper and restarted karaf. It's worked for me:
bundle:install 'wrap:mvn:org.ops4j.pax.logging/pax-logging-log4j2-extra/1.11.4'
bundle:install 'wrap:mvn:com.fasterxml.jackson.core/jackson-core/2.9.10'
bundle:install 'wrap:mvn:com.fasterxml.jackson.core/jackson-annotations/2.9.10'
bundle:install 'wrap:mvn:com.fasterxml.jackson.core/jackson-databind/2.9.10'
I use Arquillian to test an EJB that has an explicit local and remote interface. But in the test Arquillian does not "inject" anything in a field that has the type of the local interface, or the remote interface.
I use the Glassfish embedded as server for test and I use junit4.
I used :
#EJB ,
#Inject ,
#EJB(lookup="java:global/costa-services-depa/GreeterImpl!es.costa.GreeterLocal") ,
#EJB(lookup="java:global/costa-services-depa/GreeterImpl!es.costa.GreeterRemote")
With (2) even for GreeterImpl, or GreeterLocal or GreeterRemote it gives me the error Could not inject members.
With (1,3,4) I get a java.lang.NullPointerException which means that the EJB is not injected.
This is a part of my code:
#RunWith(Arquillian.class)
public class greeterTest {
#Deployment
public static Archive<?> createDeployment() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class,"costa-services-depa")
.addClasses(
GreeterRemote.class,
GreeterLocal.class,
Greeter.class)
.addAsManifestResource("test-persistence.xml", "persistence.xml")
.addAsManifestResource("jbossas-ds.xml")
.addAsManifestResource("META-INF/beans.xml",
ArchivePaths.create("beans.xml"));
return jar;
}
#Inject
GreeterImpl greeter;
#Test
public void testTestServiceLocal(){
System.out.println(greeter.getMessage());
}
}
Here is the glassfish-resources.xml:
...
<resources>
<jdbc-resource pool-name="ArquillianEmbeddedH2Pool"
jndi-name="jdbc/arquillian"/>
<jdbc-connection-pool name="ArquillianEmbeddedH2Pool"
res-type="javax.sql.DataSource"
datasource-classname="org.h2.jdbcx.JdbcDataSource">
<property name="user" value="sa"/>
<property name="password" value=""/>
<property name="url" value="jdbc:h2:file:target/databases/h2/db"/>
</jdbc-connection-pool>
</resources>
Here is the test-persistence.xml:
...
<persistence-unit name="test">
<jta-data-source>jdbc/arquillian</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.logging.level.sql" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
This is the arquillian.xml:
...
<container qualifier="glassfish-embedded" default="true">
<configuration>
<property name="resourcesXml">
ejbModule/src/test/resources-glassfish-embedded/glassfish-resources.xml
</property>
</configuration>
</container>
...
This is jbossas-ds.xml:
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.org/ironjacamar/schema
http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
<datasource enabled="true"
jndi-name="jdbc/arquillian"
pool-name="ArquillianEmbeddedH2Pool">
<connection-url>jdbc:h2:mem:arquillian;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
</datasource>
</datasources>
About dependencies for Glassfish embedded and Arquillian and Junit:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.0.3.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<profiles>
<profile>
<id>arquillian-glassfish-embedded</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
<version>1.0.0.CR3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.166</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>ejbModule/src/test/resources</directory>
</testResource>
<testResource>
<directory>ejbModule/src/test/resources-glassfish-embedded</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemPropertyVariables>
<arquillian.launch>glassfish-embedded</arquillian.launch>
<java.util.logging.config.file>
${project.build.testOutputDirectory}/logging.properties
</java.util.logging.config.file>
<derby.stream.error.file>
${project.build.directory}/derby.log
</derby.stream.error.file>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
In the console I noticed:
Infos: Network listener https-listener on port 0 disabled per domain.xml
Infos: Grizzly Framework 1.9.50 started in: 32ms - bound to [0.0.0.0:8181]
Infos: GlassFish Server Open Source Edition 3.1.2.2 (java_re) startup time :
Embedded (525ms), startup services(384ms), total(909ms)
Infos: command add-resources result:
PlainTextActionReporterSUCCESSDescription: add-resources AdminCommandnull
JDBC connection pool ArquillianEmbeddedH2Pool created successfully.
JDBC resource jdbc/arquillian created successfully.
Infos: SEC1002: Security Manager is OFF.
Infos: SEC1010: Entering Security Startup Service
Infos: SEC1143: Loading policy provider
com.sun.enterprise.security.jacc.provider.SimplePolicyProvider.
Infos: SEC1115: Realm [admin-realm] of classtype
[com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
[com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
Infos: SEC1115: Realm [file] of classtype
[com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
Infos: SEC1115: Realm [certificate] of classtype
[com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.
Infos: SEC1011: Security Service(s) Started Successfully
Infos: WEB0169: Created HTTP listener [http-listener] on host/port [0.0.0.0:8181]
Infos: WEB0171: Created virtual server [server]
Infos: WEB0172: Virtual server [server] loaded default web module []
Infos: WELD-000900 SNAPSHOT
Infos: WEB0671: Loading application [**test**] at [**/test**]
Infos: test was successfully deployed in 1 822 milliseconds.
PlainTextActionReporterSUCCESSNo monitoring data to report.
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.308 sec
Infos: Shutdown procedure finished
Infos: [Thread[GlassFish Kernel Main Thread,5,main]] exiting
NB : By default that deploys as test application or not as what I made "costa-services-depa"?
To know that in the path of call of EJB I put test instead of costa-service-depa but always it gives me the same problem (NullPointerException).
I'm having the same problem trying to somehow inject a context bean in an Arquillian test against GlassFish 4.1.
This issue seems related to a GlassFish (major and open) bug:
https://java.net/jira/browse/GLASSFISH-21167
They say injections in GlassFish won't work deploying a war with certain conditions:
The application uses an empty <absoluteOrdering> tag in web.xml
The classes of the application are all packed as jar archives in the [war]\WEB-INF\lib\ directory, instead of included them unpacked in the [war]\WEB-INF\classes\ directory
What happens to me is that my #Singleton bean is created and injected but for every #EJB reference in the app, not just created once.
I checked my Arquillian deployment on GF (glassfish-4.1\glassfish\domains\domain1\applications\test) and I can see the test.jar deployed in [war]\WEB-INF\lib\. I don't have a web.xml in my app and I don't see it in my GlassFish deployment. I guess the web.xml is provided somehow automatically.
Deploying the same app with Arquillian on Wildfly works fine and my #Singleton bean is injected correctly as expected.
This is my current test fragment:
<packaging>eclipse-test-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>com.springsource.org.junit</artifactId>
<version>4.7.0</version>
</dependency>
</dependencies>
with the following plugins configuration:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho.version}</version>
<configuration>
<dependencies>
<dependency>
<type>p2-installable-unit</type>
<artifactId>org.eclipse.equinox.ds</artifactId>
</dependency>
<dependency>
<type>p2-installable-unit</type>
<artifactId>org.apache.felix.gogo.shell</artifactId>
</dependency>
</dependencies>
<providerHint>junit47</providerHint>
<argLine>-ea</argLine>
</configuration>
</plugin>
and I use the POM-first approach to resolve dependencies:
<pomDependencies>consider</pomDependencies>
The above JUnit Version is the only one I could find, that is packaged as a bundle.
The problem is that I cannot find a match which allows me to use JUnit and Mockito together in a fragment.
My common issues are:
Mockito-core from Maven Central needs Hamcrest 1.0-2.0, but the JUnit bundle exports Hamcrest in version 4.7.0
There is no junit-dep bundle available in the Springsource repository
When I add another Hamcrest bundle, I have version conflicts between the versions exported by JUnit (4.7.0) and the Hamcrest bundle (1.3)
I would like to avoid creating my own bundle from JUnit, Hamcrest and Mockito.
I have found that the wrapper bundles of JUnit, Hamcrest, and Mockito from the Eclipse Orbit work well together.
For the (currently) latest Orbit release, which includes JUnit 4.11, Hamcrest 1.1 (with Hamcrest Core in version 1.3), and Mockito 1.8.4, just add the following snippet to your POM:
<repositories>
<repository>
<id>orbit-kepler</id>
<url>http://download.eclipse.org/tools/orbit/downloads/drops/R20130517111416/repository/</url>
<layout>p2</layout>
</repository>
</repositories>
In the wrappers of the Eclipse Orbit, the org.junit bundle exports parts of the package org.hamcrest.core. Mockito however needs the complete content of the org.hamcrest.core package. In order to prevent accidental wiring between the Mockito and JUnit bundle, the export is marked with a mandatory attribute. Unfortunately, p2 doesn't take these into account (and Tycho uses p2 for dependency resolution), so you need to give the dependency resolution of your fragment (using Mockito) an extra hint:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<dependency-resolution>
<extraRequirements>
<requirement>
<type>eclipse-plugin</type>
<id>org.hamcrest</id>
<versionRange>0.0.0</versionRange>
</requirement>
</extraRequirements>
</dependency-resolution>
</configuration>
</plugin>
This makes sure that the org.hamcrest bundle is used during dependency resolution, and that Mokito's imports can be wired successfully.
How could I set JSON provider for RestEasy at JBoss 7.1.1?
RestEasy documentation says:
RESTEasy allows you to marshall JAXB annotated POJOs to and from JSON.
This provider wraps the Jettison JSON library to accomplish this.
But I found that it seems that on JBoss 7.1.1 Resteasy uses Jackson provider because #XmlTransient on my class field was ignored, but #JsonIgnore was processed.
How can I tell to Resteasy to use Jettison instead of Jackson?
On Jboss I found both providers.
if you just want to have a different module pulled than the standard, you can provide this in a jboss specific deployment descriptor.
Read https://docs.jboss.org/author/display/AS71/Class+Loading+in+AS7 to learn the details, and read https://docs.jboss.org/author/display/AS7/Implicit+module+dependencies+for+deployments to learn what modules JBoss uses by default.
To exchange the two providers, provide a META-INF/jboss-deployment-structure.xml with the following content below.
This switched the provider for me.
Br Alexander.
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.jboss.resteasy.resteasy-jackson-provider" />
</exclusions>
<dependencies>
<module name="org.jboss.resteasy.resteasy-jettison-provider" />
</dependencies>
</deployment>
</jboss-deployment-structure>
As a follow-on to ahus1's answer: if you have a multi-level deployment archive (i.e. a top-level EAR file containing an EJB jar and a war file), you will need to configure the exclusion of org.jboss.resteasy.resteasy-jackson-provider on whichever sub-deployment contains the RESTEasy/JAX-RS components.
In my deployment, for example, my REST endpoints were annotated on top of EJBs in my EJB jar file, while my #ApplicationPath-annotated javax.ws.rs.core.Application subclass which activates RESTEasy was in my war file. I found that the approaches of putting the exclusions solely on the top-level (EAR) deployment (as in ahus1's example) or on the EJB-jar-level deployment were ineffective, but I finally got RESTEasy to use Jettison rather than Jackson by putting the exclusions on all 3 levels (EAR, EJB, Web):
<?xml version="1.0" encoding="UTF-8" ?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclusions>
<module name="org.jboss.resteasy.resteasy-jackson-provider" />
</exclusions>
<dependencies>
<module name="org.jboss.resteasy.resteasy-jettison-provider" />
</dependencies>
</deployment>
<sub-deployment name="MyApp-ejb.jar">
<exclusions>
<module name="org.jboss.resteasy.resteasy-jackson-provider" />
</exclusions>
<dependencies>
<module name="org.jboss.resteasy.resteasy-jettison-provider" />
</dependencies>
</sub-deployment>
<sub-deployment name="MyApp.war">
<exclusions>
<module name="org.jboss.resteasy.resteasy-jackson-provider" />
</exclusions>
<dependencies>
<module name="org.jboss.resteasy.resteasy-jettison-provider" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
It's very likely that I only needed the exclusions on the subdeployments, and putting it on the main EAR deployment is superfluous; I didn't try it that way, since for now putting it on all three seems to work perfectly well.
From what I observed right now, Jackson is the default in JBoss AS 7.1.2.
First, the RestEasy modules are hidden from app's classloader, which IMO should not be.
So I just filed https://issues.jboss.org/browse/AS7-5605 .
Second, to your question: To set the particular provider, you need to remove it from classloader's spot in AS - so again, to go module.xml's and comment out those providers which you don't want to use - if Jackson is available, RestEasy uses it; otherwise it uses Jettison.
Also, add them your project as a compile time dependency, so you can use their specific annotations. Example:
<!-- RestEasy -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<version>2.3.4.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.2</version>
<scope>provided</scope>
</dependency>
Note: Until AS7-5605 is done, you need to set the versions manually.
After (in later versions of AS), you have to remove these versions and use those defined in JBoss BOM. See JBoss AS QuckStarts for example.
Feel free to create and contribute a QuickStart of RestEasy using alternative provider.
I added this line to standalone.conf.bat/sh and it solved my problem.
set "JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true"