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

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.

Related

I want to use CDI with Java SE 12, but start up failes (Main Class, JBoss or Payara, all the same error)

I got completely stuck. I want to use CDI2 with Servlets to write a simple web app. However, the beans not get loaded.
I get the following error in JBoss or Payara or Weld (if running as Main Application):
WELD-001524: Unable to load proxy class for bean Managed Bean [class MyBean] with qualifiers [#Any #Default]
Does anyone still use CDI2 or has a running modern example?
I compile with maven.
warm regards,
Alex
I found it out myself. I had the wrong dependencies. I got confused because of Jakarta. I used the CDI-2 maven dependency. So I updated to Jakarta. Right? This is the way to go, right?
I can deploy. Payara-Micro works. JBoss (WildFly should do the same)
However, Payara Micro does not get track of the URL patterns of simple Servlets, although still, one can call it over the client. (Intellij has a CDI tab, gives a nice overview itself)
...
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>

Cassandra dependency changes during log4j2 migration

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

log4j2 logging of code in EJB jar on JBoss EAP 7

I am doing the following:
porting several legacy applications from WebLogic to JBoss EAP 7. Some of the components being ported are EJBs. Others are servlet apps that invoke these EJBs. These EJBs are deployed in ejb-jars. I know that I could wrap this whole thing into a big EAR file but we don't want to do that. The servlets and the EJB jars need to be separately deployable components.
Then there is the logging setup. We are using log4j2 and we want to keep independent of the JBoss logging setup. I have created a JBoss module that contains all the log4j2 jars with the proper dependencies, and logging works.
The servlet runs and logs, invokes the EJBs and they work.
The only problem is how to configure the EJB's logging. In a Web App like the servlet, it's easy, just specify the log4j logging configuration file in web.xml. What's the analog for an ejb jar? I couldn't think of a way.
I tried the following: Add a logger/appender to the configuration of the servlet app for the EJB package and specify a new file. It doesn't work. The new logfile does get created but nothing gets written to the logfile. There should be output, but there isn't, so evidently when the EJB runs, its LogManager is not using the configuration specified in the servlet.
What is the right way for specifying a log4j2 configuration in an EJB deployed in an EJB jar on JBoss EAP7?
I had previously posted in this space a solution involving use of the #postConstruct and #preDestroy methods to initialize and shut down LoggerContext objects.
This plan fell apart when I tried to extend it to stateless session beans. It worked okay for Stateful Beans. Or so I thought. Eventually I found an Oracle document on EJB Restrictions which exposed the weaknesses in what I was doing. My "solution" included a non-final static LoggerContext member of the EJB class. I found a way to make it final, which did allow the stateless case to work. But I was increasingly dissatisfied with my approach. Even in the stateful case, I found issues that might bite me later in a clustered environment.
What I now come to believe is that I should not do what I was trying to do.
I can't even imagine the complexity of what a static final LoggerContext would look like if an EJB were distributed to another machine in the cluster. Objects like LoggerContext don't belong as members, static or not, of container-managed objects like EJBs.
It's not even clear that EJBs are the right implementation technology for what I am trying to build. My use cases are not really transactional so the case for EJB implementation is not strong so one possible path leads away from EJBs altogether.
The real message is that if EJBs or other container-managed components are indicated, it's probably best to use the container-provided logging system. I like log4j2, but until JBoss supports it, it's best to stick with container-provided log4j1 or some other framework.

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.

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.

Resources