Glassfish Application specific class loading - deployment

I'm trying to deploy an EJB-JAR on Glassfish (4 or 3.1.2.2).
This EJB-JAR has some library dependencies. I would like to deploy these dependencies application specific. No other application running on glassfish should include this specific libraries.
But unfortunately, it doesn't work like described in the following link.
I always get a ClassDefNotFound-Error.
If I copy all libraries in domain-dir/lib/ext, everything works fine. But now, glassfish will include this libraries to ohter applications too. Am I right?
http://docs.oracle.com/cd/E18930_01/html/821-2418/gatej.html

Just place the library jar in the WEB-INF/lib folder of your EJB jar. There's no need to setup any additional configuration (like is specified in that link).

Related

CDI imports cannot be resolved in Eclipse

i have written an application on my pc using CDI as the backing bean for jsf, the application works completely fine.
Now i setup everything on a new pc, installed glassfish 4.1, setup eclipse kepler by putting the installed jre as jdk7 from the glassfish folder.
when i make a war for the application on my pc and deploy it onto the glassfish server on the other pc everything works fine.
now i tried taking the project from my pc and imported it onto the new pc. the eclipse on the new pc wont recognize import javax.enterprise.context.SessionScoped; giving compiler error that this annotation is not available.
The import javax.enterprise.context cannot be resolved
it doesnt recognize javax.enterprise.context.* at all. like CDI is not available. i am using JDK 7 which contains JSR 346, so i am completely confused what the issue could be.
if i deploy the application directly through the glassfish admin console using the war file it works perfectly fine but if i try to publish it through eclipse, it gives me unresolved compilation errors
Eclipse did not import ALL glassfish jars, so you need to:
Right Click on the project name, Build Path, Configure build path, under Libraries Click Add External Jars, go to where you have extracted Glassfish and import all jars that exists in:
glassfish4\glassfish\modules
and all sub directories two, like endoresed.
This will fix the problem for CDI and other stuff lik JAX-RS
If I had to guess, your .project and .classpath files are pointing to JAR locations that are specific to your old computer.
This is why people like build tools such as maven, or gradle, you can pick up and reimport a project; it'll resolve all dependencies for you.
Do you happen to use the GlassFish Tools plugin for Eclipse? I found that the GlassFish System Libraries classpath container, which is created implicitly by that plugin and which is added to all projects that specify a GlassFish server as their runtime, misses cdi-api.jar. This is where the javax.enterprise.context.* package is located (and many others).
So I could fix this by adding cdi-api.jar as an External Jar to the build path. After that, you may get a warning like Classpath entry [...]/cdi-api.jar will not be exported or published. Runtime ClassNotFoundExceptions may result., which can be eliminated by using the Quick Fix to Exclude the associated raw classpath entry from the set of potential publish/export dependencies. That JAR file is already contained in the modules folder of GlassFish, obviously.
Maybe this problem only occurs with the GlassFish Web Profile, at least that's what I use.

jBPM and JBoss web app

Ok I'm having quite some issues setting both jbpm and jboss working together...something as simple as running the jbpm process from a servlet is trunning to be a pain and all because jBoss can't find classes.
I made a Dynamic Web Project and didn't use Maven project so things are cleaner...and because it should work.
I just want to load a jbpmn2.0 from the repository in a servlet and run it using a WorkItemHanlder....but I get this:
java.lang.ClassNotFoundException: org.drools.runtime.process.WorkItemHandler
For some reason jBoss can't find a class from jBPM that should work on JBoss. What I did....and I think it's not the right solution...was add the knowledge-api.jar to the WEB-INF/lib. Although I can now deploy the app when I try to run it I get:
Error Unable to instantiate service for Class 'org.drools.builder.KnowledgeBuilderFactoryService'
I Honestly don't get why is it so hard to make a Jboss Web app using jBpm.
You need to make sure all dependencies are on your classpath, this is the same for all Java applications (not just jbpm) and application servers (not just JBossAS).
Which jars did you add? Depending on which features you are using, there could be quite a number of jars that you need to add. One option would for example would be to extract the jars in the jBPM runtime zip that is part of the jBPM downloads into your WEB-INF/lib.
If you use Maven, you would be able to automatically derive all required jars.
Kris

Eclipse doesn't import all Axis2 jars but project still runs on Tomcat?

When I develop an Axis2 web service on Eclipse, I noticed that Eclipse is automatically copying the classes from the lib folder of Axis2 to the lib folder of the new project. However, not all classes from the lib folder of Axis2 are being copied. Interestingly, the web service runs without any problem when deployed to Tomcat via Eclipse even if some the jars from Axis2 were not copied. Also, when I viewed the temp file of Tomcat, Tomcat seems to generate the jars for the listed modules on modules.list of the web service.
Can someone enlighten me regarding what is happening on this? Why Eclipse doesn't copy all the jars from Axis2? Why can the web service run on Tomcat even without the other jars from Axis2? What are those temp files for? When and why is it being generated?
I tried to run the same project on WebSphere and I am encountering a ClassDefNotFound exception because of the missing jars. My problem was solved when I copied all the Axis2 jars that was not copied by Eclipse to my project. But I'm not comfortable with my solution because Tomcat can run my project even without those jars. Is my solution really the right solution? Or am I missing a configuration setting?
This is just for clarification:
My web service is already running in Axis2. My class loading policy is set to PARENT_LAST. I know that since WebSphere has its own Axis2 configuration, the class loading policy must be set to PARENT_LAST so that WebSphere will use the Axis2 from the project itself. Aside from setting the class loading policy, I did something to make my web service run on WebSphere. I describe what I did above. My question is why such method must be taken?
WebSphere has it's own axis2 configuration as part of its Java EE server spec for JAX-WS. Change your class loading policy to PARENT_LAST and check if that solves your problem.
Edit:
As the original post already states: WebSphere is a Java EE server depending on version it supports its the standard Java JAX-WS web services. Actually web services became part of the standard jdk.
If you use JAX-WS like mentioned in Introduction to JAX-WS or building web services then you don't have to add any 3rd party library for getting your web services running. As soon as you use the non JDK implementation like axis2 you have to package it with your application.
IBM didn't just pack the axis2 into their WAS/JDK, they modified it. I'm not sure what Tomcat delivers, however as long as you use JAX-WS it shouldn't matter. With JAX-WS you don't have any direct import of the org.apache.axis packages. If you use these imports you have to supply the libraries and make sure that yours are loaded.

Is there a way to deploy exploded bundles in Apache Felix?

We are looking at rearchitecting our web application and want to move to a more modular solution, OSGi seems to meet a lot of our needs.
I've come across the Apache Felix project and taken it for a spin. It looks solid yet I find the development cycle a bit slow as it requires a maven build of the bundle(s) to make any code changes effective.
Instead I would like to be able to reload a bundle once classes have been compiled by Eclipse, without any extra building/packaging. Similar to how Tomcat and other servlet containers support deployment of "exploded" war files.
Is this possible to do with Felix or any other OSGi container?
In the Gogo shell, you can do:
install reference:file:/path/to/exploded/directory
This will install an exploded bundle. The format of the exploded directory should be exact that of a bundle JAR file.
Apache Felix FileInstall supports exploded bundles out of the box. Just install it, and put a directory with your bundle in the load directory (or configure FileInstall to look somewhere else).
Not exactly answering your question, but if you have issues with the build cycle, you should take a look at bndtools, which is a plugin for Eclipse that a.o. automatically builds and deploys your bundles in a running framework when your code changes.

About Java EE classpath

I am developing an online conference system based on Java EE framework using NetBeans for my school. My project contains the Java EE library which has javax.mail package.
I use the javax.mail.authenticator class in my code and everything seems to be OK. However, when I run the project and try to send email with this system, problem occurs, saying it can not find class javax.mail.authenticator.
Then I put the files mail.jar and authenticator.jar in folder WEB-INF/lib, after that it can send email correctly. I don't know why it can not find the class authenticator and why this two jar files should be put there?
PS: I use Tomcat 6 as my web server.
There is a difference between having a class on the Java build path, and on the classpath. By putting mail.jar and authenticator.jar into WEB-INF/lib, you have put them into Tomcat's classpath so that Tomcat can "see" those classes at runtime.
Recommended reading: What is the difference between Class Path and Build Path
P.S. I think you mean Java EE. It hasn't been called J2EE for ~5 years now.
When you deploy an application to a Java EE container, like Tomcat, there are certain places classes and jars are loaded to form an application's classpath. For web applications (a war), classes are loaded from WEB-INF/classes and from jars in the WEB-INF/lib.