JBoss 7 add jar to classpath - java

I'm trying to deploy WAR file into JBoss 7.
I placed the WAR file in the standalone/deployments folder.
while starting the server I’m getting ClassNotFoundError.
I believe Since the jars are not part of the WAR file and not placed in the WEB_INF/lib folder so I need to add them externally.
I read so many tutorials but I just can’t understand how it works.
So my question is how I simply add JAR files to the JBoss classpath.

If you want to add any jars that are not part of WebApp but are still needed to be loaded, one approach would trying to copy the jars at following location:
$JAVA_HOME/jre/lib/ext.
The JBOSS server should point to this java installation and this might resolve your issue.
This might be one way.
JBOSS 7 uses module based loading, hence most of the jars will be loaded if module is included in standalone.xml.
You will need to check in JBoss Release notes if third party modules can be loaded.

Ok I solved it by creating new module and by adding the module dependency in the MANIFEST of my jar.

Related

NoClassDefFound - org/apache/kafka/clients/producer/KafkaProducer

I have an ear file, inside ear file I have the war file. Its based on Spring 2.5.6 and jdk 1.6
now I want to publish few messages to kafka, included kafka-clients-1.0.0 in war/web-inf/lib
but its getting NoClassDefFoundError org/apache/kafka/clients/producer/KafkaProducer.
NoClassDefFoundError usually happens when your project has conflict dependencies, for example 3rd and 4th versions of Spring framework. Check your dependencies and their transitive ones.
It simply means the class which you are trying to run was not found in on your classpath.
Solution: you need to add the class or .jar file which contains this class into the java classpath.

EJB Timer (#Schedule) not recognized by WildFly when inside a JAR which is also inside an EAR

I have an EAR file with 3 WARs and some common dependencies within lib/ folder. One of those dependencies has an EJB with a scheduled method, but it seems that the server is not recognizing it. No evidence in log, no code executed.
But when I deploy a simple war with the same jar within WEB-INF/lib, it works. I've already tried to package the jar as an ejb-jar with the maven plugin, but no success at all.
Any ideas on what must be going on?
Jars in the lib directory of an EAR are not considered to be EJB jars and their content is not considered at deployment time in that respect. The lib directory only exists to make it easier to provide library jars whose classes are automatically made visible to all the modules in an EAR file.
Your EAR file contains a META-INF/application.xml file that lists out the various modules that it contains. Prior to Java EE 6, only ejb-modules were considered for potential EJBs. Java EE 6 and newer added web-modules to that list. All jars within a web-module's WEB-INF/lib directory are considered to be part of the web-module, even if they contain ejb-jars. Any ejb-jar.xml files found within a web-module are merged together. This applies even if the web-module is deployed as a standalone WAR file.

Deploying a war file created by maven to a glassfish server, determine the order of the classpath?

Setup
I have a maven project which creates a war file, I then deploy the war file to a glassfish server (3.1).
My Manifest is default one with just the basic info, but I've also tried maven-war-plugin to add classpath to the Manifest. From my understanding of that plugin it should only help me determine libs outside my web-inf/lib scope.
Problem
In my war file I have two dependencies which both contain the same class but two different version of that class, so I need to specify my Glassfish Archive class loader to load them in a certain order. Now I'm completely lost as how to do this, which leads me to my questions.
Questions
Is it possible to use the Manifest file to force Glassfish to use a specific classpath?
How does Glassfish determine in which order it loads the jar files in WEB-INF/lib?
Is it possible to tell Glassfish how to specify the classpath in some other way?
If not, is it possible to affect the order Glassfish loads the jar files in WEB-INF/lib?
(I don't have privileges to comment in SO, hence the answer)
The following link describes one way of managing the order of class loading.However, as others have rightly pointed out, what you are trying to achieve is not good at all.
https://www.java.net/node/704037

Glassfish and Java EE external JAR

I am trying to use postgres on a EJB in a EAR, but i keep getting the error:
java.lang.ClassNotFoundException: org.postgresql.driver
so my app is not finding the jar. According to what I saw here: How to use 3rd party libraries in glassfish?, I should put the jar on either glassfish3/glassfish/domains/domain1/lib/ext or glassfishv3/glassfish/domains/domain1/lib, I tried both and is not working.
I was also not sure of something, should I add the jar to that folder and then reference the build path (using netbeans) of my app to the jar on that folder? or should I omit this step?
Anyhow, I tried both, referencing it and not doing it (only adding the jar to the folder in glassfish) and is not working.
So, how can I add an external jar to my application (EAR) that is put on a glassfish cluster?

eclipse tomcat why does it keep copying the servlet api jar

I am using eclipse and added tomcat 6 server. whenever i try to start the server it automatically copies the server api jar into the WEBINF/lib folder and the app does not start
INFO: validateJarFile(/media/01CB9CAC704E03A0/Projects/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/myapp/WEB-INF/lib/servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
I got the same problem and finally got it to work after looking at this among other pages. I am going to list it here in case other people run into the same issue.
In my case, the myeclipse project was created from a maven .pom file which lists the JEE 1.5 files as "provided" scope i.e. these files will be provided by the container (in my case tomcat 6). So if I create a war file using maven and drop it in the webapps dir it just works fine. It gets a little tedious doing that every time you make a change, so I decided to go for exploded deployment and thats when I ran into the same issue.
Since the project file was created from the pom file, these dependencies came in but Eclipse project file does not recognise these as "provided" and not to be deployed. And TOMCAT is not happy when it finds two implementations of the spec:
"Servlet spec 2.3 sec 9.7.2 recommends … The classloader that a container uses to load a servlet in a WAR must allow the developer to load any resources contained in library JARs within the WAR following normal J2SE semantics using getResource. It must not allow the WAR to override J2SE or Java servlet API classes. It is further recommended that the loader not allow servlets in the WAR access to the web container’s implementation classes. It is recommended also that the application class loader be implemented so that classes and resources packaged within the WAR are loaded in preference to classes and resources residing in container-wide library JARs."
I toyed with the above solution to change my deplyment assembly config but that is not helpful alone since these jars get bundled in if I select the "JARS from the build path"
in the menu project properties/MyEclipse/Web/Deplyment/Configure workspace settings.
And I need to do that cos I have other dependencies jars (not provided by container).
Solution:
I removed these jars from the dependencies in the build path manually.
Instead I added a dependency on User Library - JAVA EE5.
And in the deployment configuration I removed the option of JARS exported from User Libraries of required projects.
YMMV. But in any case if you read the servlet spec definition above and then look at the config in your workspace, you can sort it out.
Hope this helps.
Go to your project properties and look under Deployment Assembly page. This page describes how your app will be packaged for deployment or export. Take a look at entries regarding libraries. You have to figure out which of those entries points to the servlet api jar and remove it. If the entry points to other jars that do need to be packaged, you will need to split it into several separate build path entries, so you can tell Eclipse exactly what does and does not need to be packaged.

Categories