Cassandra dependency changes during log4j2 migration - jar

I am migrating my application from log4j to log4j2. For this I have replaced the jar files for log4j with log4j2 and updated the corresponding API calls to use the new jar.
We also have cassandra noSQL db which has slf4j-log4j12-1.7.6.jar as dependency which in turn uses log4j APIs. I would need to replace slf4j-log4j12-1.7.6.jar with a new jar which is compatible with log4j2. Can someone suggest the correct jar to be used?
I am getting below exception while building cassandra components.
Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: org/apache/log4j/Level
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150) at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124) at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)

The NoClassDefFound error indicates SLF4J is looking for Log4j 1.x. You need to replace the slf4j-log4j12 jar with Log4j 2's log4j-slf4j-impl jar.

This is resolved now by adding log4j-to-slf4j-2.9.1.jar and removing slf4j-log4j12-1.7.6.jar.
Below links helped.
https://logging.apache.org/log4j/2.0/log4j-slf4j-impl/index.html
http://slf4j.42922.n3.nabble.com/trouble-migrating-from-log4j-1-2-to-log4j-2-0-td4025759.html

Related

what Jar's are needed for and ActiveMQ client, application

I have activemq-client-5.13.3.jar on my class path, but i keep getting
Exception in thread "main" java.lang.NoClassDefFoundError: javax/jms/JMSException
If i use activemq-all-5.13.3.jar on my class path, every thing works.
however I am not allowed to use the activemq-all jar.
added jms-api-1.1-rev-1.jar
and now Exception in thread "main" java.lang.NoClassDefFoundError: javax/management/j2ee/statistics/Stats
You can use maven to determine this with the mvn dependency:tree command or use other maven centric tools to explore the artifacts dependencies.
At a minimum you would need these for v5.13.3
slf4j-api.jar geronimo-jms_1.1_spec.jar hawtbuf.jar
Then you can add an slf4j binding like log4j or logback to get proper logs. There are some others that you might want depending on where / how you are using it like the geronimo-j2ee-management_1.1_spec jar.
Of course if you use maven to build you can make this simpler since it will manage the deps for you.
I found same problem with my java application. I needed to insert Spring Boot for rest web service (Jetty Server) and now ActiveMQ for others data exchange.
With
activemq-client-5.15.11.jar; geronimo-jms_1.1_spec-1.1.1.jar; geronimo-j2ee-management_1.1_spec-1.0.1.jar; hawtbuf-1.11.jar;
all works.

List of jars Jetty-8 scans

I am using a Java Application that runs on Jetty-8.
Is there any ways to have the lists of all jars that Jetty scans..
Can we print something (like jar's name or something) when jetty executes those jars.
update
The core issue is jetty-8 slow startup.
I already added metadata-complete="true", and startup time has decreased.
But the problem here is to validate this concept
"metadata tag skips scanning jars of our web application."
Just to do an experiment I have made following changes :
Try 1 :
Removed All meta data tag from web.xml
Jetty log level mode changed to DEBUG.
What I have found in debug level logs is its scanning all jars of my web application. [ That is OK]
Then,
Added metadata tag and restarted server and found it is processing same means its scanning the jars of my web application.
Here I am looking for the ways that make sure that metadata tag is skipping scanning jars from my web application.
There is a command
java -jar start.jar --dry-run
lists all the dependency jars with classpath.
java -jar start.jar --help
gives you detailed usage of start.jar
Note: Jetty 8 is EOL (End of Life). You are strongly encourage to upgrade.
The metadata-complete="true" attribute on the WEB-INF/web.xml does not prevent JAR scanning.
It merely states that the metadata is complete, and should not be modified, as a result of scanning for other metadata sources (like web fragments, class annotations, etc.)
However, there are other features of the Servlet Spec that are not metadata related, and require jar/class scanning to even function. See javax.servlet.ServletContainerInitializer and its #HandlesTypes annotation for an example.
If you were using Jetty 9, then you could control the list of jars that are scanned.

websphere ejb deployment issue : classnotfound error for other ejb references

I have two ejb jars packaged into a ear. say EJb1.jar adn Ejb2.jar. I am deploying it in Webphere 7.0. Ejb1 is referencing to classes in Ejb2.jar. Unless I specify the Ejb2.jar in Manifest.Mf file of Ejb1.jar, the deployment of EAR file fails.
Throws error that build path is incomplete and that referenced class is not found.
Is there any way I can overcome this ? Through some settings in WebSphere console?
I have too many ejb's in this ear referencing each other.
It makes things really difficult to update manifest file each time we make code changes.
Any ideas ?
If you want to avoid that what you need to do is create and EJB Client Jar which holds the interfaces and put it in the EAR/lib directory.
For example if EJB1.jar got MyBean.java and MyBeanLocal.java you will now split it to 2 jars files:
EJB1.jar (EJB Module) holding MyBean.java and EJB1-Client.jar (Utility Jar) holding MyBeanLocal.java
Then you put EJB1-Client.jar in the EAR file lib directory and EJB2.jar will be able to find the interfaces in its classpath.

CDI on GlassFish 3.1.1 b12 generates error "WELD-001408 Unsatisfied dependencies"

I'm trying to evaluate CDI on Glassfish 3.1 and even though I have accomplished to make it work well, when I'm trying to split my code in separate deployment modules I get a weird error. More specifically:
I have two classes bundled in the same utility project (let's say the CommonLib.jar); the classnames are UserDatabase and UserDatabaseEntityManager and their definitions are as below (in the PS at the end of this message).
I also have an EAR with an EJB3.1 module in it.
When I choose to deploy the CommonLib.jar as a "Bundled Library" of the EAR, then I get the following error:
Error occurred during deployment: Exception while loading the app : WELD-001408 Unsatisfied dependencies for type [EntityManager] with qualifiers [#UserDatabase] at injection point [[field] #UserDatabase #Inject com.test.TestEJB.itemPersistenceEm]. Please see server.log for more details.
Same error as above I get also when I deploy the CommonLib.jar as a shared library (jar file copied under $glasshfish_installation_path/domains/domain1/lib)
BUT, if I choose to just have the two classes (UserDatabase and UserDatabaseEntityManager) in the EJB project (thus they are compiled within the EJB module), then the injection works fine.
Am I facing a classloader issue? Any ideas how I can get past this issue?
Just a guess, because I faced a very similar problem with Glassfish and CDI a few days ago: Do you have a beans.xml in every JAR, i.e. in the CommonLib.jar and the EJB JAR, so that CDI scans both of them?
My problem resulted from the fact that I thought placing a beans.xml into the EAR would be sufficient, which is not the case.
Sounds like you're running into some of the Glassfish CDI integration issues we've found while working on Seam 3. It could be a couple of them, so you'll have to take a look at see which one it may be. Try testing on JBoss AS7 or Apache TomEE and see if you still have problems.

include model libraries in appclient jar

I'm deploying an ear with an EJB onto glassfish 3.1 which I want to call using the appclient script.
The EJB has a method with as parameter a model object which is defined in a separate library.
If I want to use the appclient script I have a Main class with a main method which calls the EJB.
This is also put into a separate jar which is also deployed onto glassfish.
As the model object is located in a separate library I need it in the client jar but also in the EJB.
So I need to reference it somehow in the client jar.
The client jar is a jar (duh) so I cannot add other jars. The Java EE 6 docs say that I should create an ear with the libs but if I do that it doesn't deploy because an ear needs at least an ejb or web module and my client lib has neither.
The solution I found is using the assembly plugin/jar-with-dependencies. This plugin creates a new jar which contains all classes of all dependencies.
This solution works but I'm wondering if this is the way to go or I'm missing something obvious because I cannot imagine this is required. EJB's usually have model objects as parameters so this situation will happen a lot.
So my question is: is there a way to tell glassfish to reference the shared libraries between the app client jar and the ejb jar.
The way I do this is like this:
Separate Maven project with the model. In my case that's a bunch of simple POJOs with JPA and JAX-B annotations, some constants, etc. In Maven, I define this as an OSGi bundle, by specifying <packaging>bundle</packaging>. I call this project MyAppInterface.
Separate Maven projects for other elements that need to deal with the model. In my case, I have one Java EE application with EJBs, Database facade, REST servlet; I have an Integration-Test project which only does tests; a GWT application; etc... In those projects I specify the dependency to the model:
<dependency>
<groupId>com.skalio</groupId>
<artifactId>MyAppInterface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
When deploying MyAppInterface to Glassfish, I use the following syntax:
asadmin deploy --type osgi --name MyAppInterface /path/to/MyAppInterface-1.0-SNAPSHOT.jar
I understand it that this is placing the model on the classpath of Glassfish, similar to a mysql-connector, only OSGi-style.
I let all these projects be built by a central jenkins CI server, which deploys the artifacts to our internal maven repository. We then add the internal repository in pom.xml of each project. As a result, everyone automatically works with the latest stable MyAppInterface, even if they don't have the code checked out in NetBeans / Eclipse.
Let me know if you need more examples.

Resources