Wildlfy 10 deployement - NoClassDefFoundError: org/picketlink/common/exceptions/ProcessingException - classloader

I'm overriding a server filter class from a jar in the Wildlfy 10 modules.
It's a quick and dirty solution : copied/pasted the content of the class in my custom class and referenced my custom class instead.
My parent pom is like this :
<dependency>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-api</artifactId>
<version>${picketlink-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-federation</artifactId>
<version>${picketlink-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-common</artifactId>
<version>${picketlink-version}</version>
<scope>provided</scope>
</dependency>
And I have the following section in the war pom containing the custom class :
<dependency>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-federation</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-common</artifactId>
<scope>provided</scope>
</dependency>
I also have a jboss-deployment-description.xml file in my war where the package containing the missing class is already referenced (this is from an instruction on how to use the package for other things) :
<jboss-deployment-structure>
<deployment>
<!-- You must configure the PicketLink dependency to your deployment. The dependency above is a reference to a static module
from JBoss EAP modules directory. -->
<dependencies>
<module name="org.picketlink"/>
<module name="org.picketlink.common"/>
</dependencies>
</deployment>
and the main package "org.picketlink" is also in my ear's manifest file which packages the war :
<manifestEntries>
<Dependencies>
com.docapost.configuration,org.picketlink
</Dependencies>
</manifestEntries>
This was also done to solve some past ClassNotFoundException in the past if i recall correctly.
The jar version in the pom is the same as the version in my Wildfly (picketlink 2.7.0.Final)
At deployment, I get the exception from my custom class ZephirSPFilter :
Error getting reflective information for class com.docapost.zephir.filters.ZephirSPFilter with ClassLoader ModuleClassLoader
And :
Caused by: java.lang.NoClassDefFoundError: org/picketlink/common/exceptions/ProcessingException
Caused by: java.lang.ClassNotFoundException: org.picketlink.common.exceptions.ProcessingException from [Module \"deployment.zephir-ear.ear.zephir-web.war:main\" from Service Module Loader]"},

As far as I understand you have ear and included in it war. And you added jboss-deployment-description.xml to your war. But this file should be placed in the top level deployment, i.e. in your case to ear.
See https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7

Related

pom file Build failed found duplicate classes/resources: THIRD_PARTY_LICENSES.txt

Maven build fails with the following error. I need all three jars in pom for compilation dependencies. But the duplicate finder throws the following error:
Found duplicate (but equal) resources in [com.oracle.oci.sdk:oci-java-sdk-common-httpclient:3.2.1, com.oracle.oci.sdk:oci-java-sdk-common:3.2.1, com.oracle.oci.sdk:oci-java-sdk-vault:3.2.1]: THIRD_PARTY_LICENSES.txt
pom.xml
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-vault</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-common</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-common-httpclient</artifactId>
<version>3.2.1</version>
</dependency>
How do I fix this error? Thank you

How to inject a Spring bean in a JUnit 5 test class written in Kotlin?

I try to test something in a Kotlin project using JUnit 5 and Spring Boot, but I'm unable to inject a bean in my test class.
I tried many different annotations, but the injection nerver worked...
Here's my test class:
#TestInstance(TestInstance.Lifecycle.PER_CLASS)
#SpringBootTest
#ExtendWith(SpringExtension::class)
class FooTest {
#Autowired
lateinit var repo: BarRepository
#BeforeAll
fun setup() {
}
#Test
fun testToto() {
}
}
With this annotations combination, the code raises the following exception:
java.lang.NoClassDefFoundError:org/springframework/boot/context/properties/source/ConfigurationPropertySource.
And I'm actually unable to find where does this exception come from... I tried to do some research about this exception, but I didn't find anything satisfying...
I finally found how to fix my problem. My Spring Boot version was initially "1.5.3", so I changed it my pom.xml to the "2.0.2" version. Now my tests run fine and my bean is correctly injected as expected. Here's the modified part of my pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/>
</parent>
Everything is fine after modifying the version.
Here are the usefull dependencies to test with Junit:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
I guess you have an error in your dependencies. If you generate a new Spring Boot Kotlin project from https://start.spring.io/#!language=kotlin then customize your dependencies as following, it will work as expected:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Please also notice that you don't need to specify #ExtendWith(SpringExtension::class) since #SpringBootTest is already meta annotated with this annotation as of Spring Boot 2.1.

Maven dependencies for Hadoop: MiniDFSCluster & MiniMRCluster

I want to implement a maven project, that helps me unit test a Hadoop MapReduce job. My biggest problem is defining the Maven dependencies to be able to make use of the test classes: MiniDFSCluster & MiniMRCluster.
I am using Hadoop 2.4.1. Any ideas?
In case someone else is still searchinf for an answer:
MiniMRCluster is now deprecated.
You can get MiniDFSCluster and MiniMRCluster in the dependency (shown for Gradle)
compile group: 'org.apache.hadoop', name: 'hadoop-minicluster', version: '2.7.2'
The dependency is basically just a pom file that lists out the dependencies in this package. For those who want to look this up, MiniDFSCluster is in the artifact hadoop-hdfs:tests
You don't have to use the dependencies from the Cloudera repository
Guess I figured it out. In your Maven pom file, first add a new repository:
<repositories>
<repository>
<id>cloudera</id>
<url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
</repository>
</repositories>
Then add the following to your project dependencies
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-auth</artifactId>
<version>2.0.0-cdh4.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-test</artifactId>
<version>2.0.0-mr1-cdh4.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.0.0-cdh4.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.0.0-cdh4.3.0</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.0.0-cdh4.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.0.0-cdh4.3.0</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>2.0.0-mr1-cdh4.3.0</version>
</dependency>
In case someone is interested to get the whole project (unit test for the famous WordCount MapReduce job, I am willing to share it)

How to tell JMockit not to override behavior of custom junit runners designed for integration testing

I have the following test method
#RunWith(MyCustomJUnit4Runner.class)
public class MyIntegrationTestWithACustomIntegrationRunner{
#Test
public void ensureStuffIsWiredCorrectly(Dependency myDependency){
}
}
This method is ran with a custom runner that injects the wired dependency.
JMockit also injects mocks in this scenario.
Normally I would want the jmockit behaviors, however this case I need the platform injected item rather than the mocked version.
Any advice would be appreciated.
Please feel free to comment on how I can clarify the obviously ambiguous question.
pom entries:
<dependencies>
<!-- CUSTOM INTEGRATION RUNNER -->
<dependency>
<groupId>com.clinkworks</groupId>
<artifactId>neptical</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>[4.0,5.0)</version>
<scope>test</scope>
</dependency>
</dependencies>
You will have to upgrade JMockit to version 1.7 or newer:
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.8</version>
<scope>test</scope>
</dependency

Getting java.lang.NoClassDefFoundError while using solr-solrj-3.6.1.jar

Using Solrj to connect to solr indexes. Used jar solr-solrj-3.6.1.jar which I got by adding below maven dependency
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>3.6.1</version>
</dependency>
I see that CommonsHttpSolrServer is deprecated and hence using HttpSolrServer . During run time i get the below error,
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
Just adding solr-solrj-3.6.1.jar is not sufficient? Should I have to add more dependencies? I also tried adding httpclient 4.1, It started asking for org/apache/http/HttpRequestInterceptor.
Add this package to your maven dependencies:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.1</version>
</dependency>
Added below dependencies to get this working
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
</dependency>
My simple project of solrj uses the following dependencies:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
</dependencies>
Between, Maven can automatically download them (for example, I started the Java Application of Maven in NetBeans, and then just added the dependencies). Additionally, I needed just to download the library of commons-logging 1.1.3 (http://commons.apache.org/proper/commons-logging/download_logging.cgi). You can read more about libraries and dependencies here: (http://wiki.apache.org/solr/Solrj).