Referring shared Java EE library for EAR application in weblogic - java

I have created a shared library with some jar files in weblogic server, now I have an EAR application and I want to use the class files from shared library in my web applications present in EAR application. So I have created weblogic-application.xml file inside my ear-app/META-INF/ directory and gave reference to shared library using below tags:
<library-ref>
<library-name>ebs_endeca_artifacts</library-name>
</library-ref>
But when I am trying to access the class files in my application, I am getting exception java.lang.ClassNotFoundException
Also it is required for me to refer to the shared library at ear level instead of declaring in weblogic.xml file of individual war files.
If I directly place the same jar files in my ear-app/APP-INF/lib directory instead of using shared library then my application is working fine without any issues.
Please help me how can I use the shared library in my ear application. I am using weblogic server 10.3.6
My shared library structure will be like this:
shared-web-app/WEB-INF/web.xml
shared-web-app/WEB-INF/lib/*.jar

You need the jars from the shared library in your classpath, because before you deploy the EAR, the application needs to be built. JDeveloper wouldn't know where are those classes stored, so that it need those at compile-time.
When preparing the application for deployment, you can create filters for the files that can be added within the WAR/EAR/<whatever>. Go to Application Properties -> Deployment and select your deployment profile. Click on the Edit button and a screen will be prompted, from where you can filter the files/libraries that can be included when the application is built.
If you don't include the shared library in the archive and have the fragment from the weblogic-application.xml you've posted, the WebLogic server will then use the classes from the shared library.
Hope that helps. Ask anything you don't understand as a comment. :)

Related

usage and significance of .Classpath in Application EAR

I am currently working on an EAR application which has a WEB project and EJB project in it.
To work on eclipse with local set up i do so many build path setups and all.
All these buildpaths show up in .classpath of the project.
Now when i export the EAR and deploy on Server everything works on server.
My doubt is how does server know about my local system paths which are present in .classpath of my project.
Does it mean .classpath has no significance at runtime?
Please explain.
.classpath file is eclipse specific, it will not be bundled with the EAR. Eclipse uses it to set the classpath for the project.
An EAR has a well defined structure and Servlet container understands that structure, using it's knowledge it prods around in the EAR file and extracts classes to load in the runtime.
Obviously server doesn't have any knowledge of your local environment. An EAR (or WAR or JAR) file is a simple archive file (with some specification or the file order and all). You can unzip it using any utility (something like 7zip). Check the structure of the packed EAR, that will give you a better understanding of what goes to your server.

Library is not copied to Tomcat directory when deploying

I am developing a JSP application to test calling a servlet with AJAX that returns a JSON object. I am using Eclipse as IDE. As library for processing JSON I am using Gson. To make that library available in my project I created a lib folder inside my source directory and copied the Gson library into it. After reloading the project in Eclipse I included it in my build path. I can use that library in my classes with no problem.
I configured the JSP application to be deployed to my local Tomcat installation. When running the application everything gets deployed to .../tomcat/8.0.26/libexec/wtpwebapps/AjaxJson so that part is working. As I understood it the directory WEB-INF contains all the classes and libraries. The classes directory contains all the classes I defined, but the lib directory is empty. Thats the reason why everytime a servlet is requested that uses the Gson library I get a java.lang.ClassNotFoundException. What do I have to do to get Eclipse to copy libraries into the lib directory when deploying the application?
Check the mappings in web deployment assembly in project properties. If you use maven, there is no need to copy dependencies manually.
It's been a long time since I used Eclipse for building WARs, but I think that marking the library as exported in the project Build Properties dialog will do the trick. If not, please do downvote.

How to Deploy Java EE Project which reference external JAR files in weblogic

I have a web application which consist of JSP pages, Servlet and Consumes Web Services.
It also references apache axis and excel libraries.
Now I want to deploy my application directly in Weblogic server
How do i do that.Whcih archive shud i make WAR or JAR??
ALso how to ensures that it covers all the referenced libraries.
I have made my application in Jdeveloper, but I dont want to deploy it using Jdevelper..
I would package my solution as a .war file, containing all dependent .jar files.
That way your solution is self-contained. You can deploy to an app server containing other apps with their own versions of your libraries (dependent or developed). If you put the dependent jars directly into the app server (as you can do), then you're forcing those versions on all applications deployed, and that could well cause you grief.
The downside is that your developed .war file can become sizable. It's not normally a major problem, and I wouldn't worry about it until it's identified as an issue.
A JAR-file cannot contain a JAR-file, so that option is out. Since you mention JSPs and servlets a WAR would seem the appropriate option, although an EAR with a WAR and several JARs could also be a way forward...
Cheers,
Consider a WAR with your JAR files in WEB-INF/lib. Or, create an EAR with APP-INF/lib folder.

How hard is it to load JARs from another location?

I have the following scenario. I'm working with a server which has a lib folder which contains all of its JARs, but things get kind of complicated when having multiple applications for the server, as the lib directory gets kind of crazy.
What I'd like to do is put all of my application's JARs in a different location and instruct the classloader to load them when my application is loaded. How can I do this? How will I need to rewrite my application to facilitate this?
As far as I know, it is not possible to load the jar files or set the CLASSPATH at runtime unless you have written your own class loader. Tomcat is a good illustration in which the tomcat's class loader loads the jar files dynamically in multi-level.
http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html
There is a common class loader which allow the jar files to be shared accross all web application. However, if you want to addthe jar files which are only loaded for the web application then you should add it under webroot, e.g. WEB-INF/lib. The libraries in this folder are not shared to all applications. For example, this means if two web applications are using different versions of the same library, they will not be mixed up.
Since I am using maven to manage the project, I do not need to worry about where to put my ja dependencies. Maven automatically bundles the libraries into war file for me.
So if you are not using servlet container, e.g. tomcat, jetty, etc. , then you will need to write a class loader. If that is necessary, then have a look into tomcat but it may not be easy.
You can add directories to the class path in Java 6.

When releasing a java spring web application, what are the steps to deploy/release?

If I make a spring mvc application, what are the things I have to do to deploy the application? (say its a commercial application)
What options do I have? Do all applications compress the classes into a .war file?
/WEB-INF/web.xml, appname-servlet.xml, etc.
/WEB-INF/jsp/*.*
/WEB-INF/appname.war ???
Done correctly, the build process will create a war which can be dropped into any servlet container (Tomcat, Jetty, Glassfish).
If you use external source files, those would have to be configured.
If you use advanced features provided by the servlet container, the server would have to configured as well.
Spring application is no different from any java web application when deploying. but generally the only thing I have to do is flip the order of test spring config with the actual one.
Any IDE could create the WAR file for you. As you've said the configuration xml files go to /WEB-INF folder and jsp files (by default) to /WEB-INF/jsp/. You also need to put all required jar files in /WEB-INF/lib folder. Compiled classes will go to /WEB-INF/classes, but let the IDE do that for you.
The war file shouldn't be in the /WEB-INF folder. In Tomcat for example you need to copy it to the webapps folder.

Categories