websphere ejb deployment issue : classnotfound error for other ejb references - ejb

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.

Related

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.

Jasper Reports NoClassDefFoundError

I'm getting a NoClassDefFoundError error when trying to compile or run a Jasper report.
2012-06-13 14:46:26,710 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/jahtest].[jahtest]] Servlet.service() for servlet jahtest threw exception
java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.xml.JRXmlDigesterFactory
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:207)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:172)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)
I have a set of java classes wrapped up in a war file and deployed in JBoss default/deploy folder.
I have the jasperreports-4.1.2.jar file in the JBoss default/lib folder so I can't see how there can be a classpath problem because all other jars in the lib folder can be seen.
My front-end app calls a HTTPServlet class which then uses reflection to call the class containing the Jasper code. Everything works fine up until the point where this line is called -
JasperDesign jasperDesign = JRXmlLoader.load(strCompiledReportFile);
The strCompiledReportFile is correct and exists. This all works when I run it through Eclipse, just not when called from my HTTPServlet class.
I'm at the point where I want to ditch Jasper because I've had so many issues with it so this is the last chance saloon.
Cheers for any help you might be able to offer.
I think you are missing few jars that jasper depends on at runtime. Check this thread and make sure you have those jars in your classpath as well.
I'm not sure if it would also apply to your case, but I had a similar problem recently, where after failing to load a font ("problem reading font data"), Jasper Reports would start giving spurious java.lang.NoClassDefFoundError for many of its classes; this problem was caused because java.awt.Font.createFont(int fontFormat, InputStream fontStream) tried and failed to create a temporary file. The error happened inside Tomcat, but not inside Eclipse; what was happening was that Tomcat automatically configures its JVM to point to its temp folder instead of the default one, and Tomcat's temp folder had been deleted.
If you are trying to integrate jasper with springboot application check whether the .jrxml is in the resources folder.

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.

problem with the injection of an EJB that resides in a jar

I have some problems regarding the EJB injection and I haven't been able to find a solution anywhere.
My situation is the following: I have an EAR file that includes a WAR and several JARs, all listed in the application.xml file. All is working fine for this part.
The problems come out when I try to add what we can call a “plugin system”.
I have a JAR with inside some .xhtml pages, backing beans and EJBs. This JAR, if needed, is inserted inside the EAR in a specific directory (let's call it “plugins”) and is detected from the application at startup.
When the JAR is detected it's path is added to the WAR class loader so all the pages and the backing bean are detected without problems. What is not working is the injection of the EJBs (I tried to use the notation #EJB, #Inject, the lookup...). I can't inject any of the EJBs that is inside the JAR plugin.
My guess is that the application server treats the JAR as a simple library module and doesn't look for any EJB inside it, so they are inside the JAR but not usable from the application.
My question is: there's a way of having this working? I tried to add the JAR in the EAR's MANIFEST.MF but nothing changed...
the application server i'm using is glassfish 3.0. About the application.xml: there's no reference in it about the JARs that are part of what i called "plugin system". This because i detect them when i deploy (or i restart) the application in the application server, so they may or may not be inside the system and i don't really know that before the system is started.
Each plugin JAR is a "collection" of pages and functionalities that can be added or removed from the system dynamically (more less like a real plugin system).
My EAR structure is the following:
MyApp.EAR
META-INF
lib
plugins
plugin1.JAR
app.WAR
logic1.JAR
logic2.JAR
for example: in the application.xml i have the references for app.WAR, logic1.JAR and logic2.JAR (they are always inside the system), at startup the application looks inside the folder "plugins" for any plugin (specific JARs) to be added to the system.
I hope i've been more clear about what i'm trying to do...
It seems that the EJB are not even registered in the JNDI tree of the server. Which application server are you using? You can have a look to this JNDI tree to see if the EJBs are there, but the way to do this depends on the specific server.
How are you declaring the JAR that contains the EJBs in the EAR application.xml?
It should be someting lide this:
<application>
....
<module>
<ejb>nameOfTheJarFile.jar</ejb>
</module>
</application>
The Jar should be in a the "/lib" directory of the EAR.
I hope this helps.

How to make an application client jar file for IBM's launchclient

Hi I'm facing with a bug in old ejb application which is deployed on IBM Websphere 6.1. Previously it ran but now it stopped for some reason which I have to investigate.
I'm trying to get it to run locally on my desktop, and I'm trying to access the session bean with IBM's launchclient application. I pass in the ear as the argument (yes that's IBM specific) and the ears contains both the ejb-jar and the ejb-client.jar (also IBM specific).
Launchclient fails with the message: myear does not contain an Application Client jar file. Which may be true, but it does contain the client-ejb jar file, which I even bothered to address with -CCjar=MyEjbClient.jar.
My question is how can I make an application client jar file?
I cant find much information on the launchclient thing, I do have RAD 7.x or something, but to be honest I want to stay away from it as much as possible and it's getting really frustrating.
regards,
PS someone knows a nice NO IBM job?
It is not sufficient to have an ejb-client-jar, you need an application client JAR. Also, -CCjar can only be specified for an application jar (and it's not necessary if you only have one).
To add an application client JAR to an EAR, you need to:
Create a Java class with a traditional main method.
Package the class in a JAR in the EAR.
Add a Main-Class to the META-INF/MANIFEST.MF in the JAR.
Add a META-INF/application-client.xml file to the JAR.
Add the module to application.xml in the EAR:
<module>
<java>MyClient.jar</java>
</module>

Resources