My Project has 2 java files (A.java and B.java in same package). A.java uses methods in B.java. And, an external jar has been added in the project build path. In order to create a web service (bottom up) from the class, I created a new Dynamic Web Project in Eclipse with axis2 as the runtime platform, and imported A.java and B.java source files. Next, since all my methods that need to be exposed are contained in A.java, I right click on it and created web service using the standard settings. When I deploy the web service on my apache, I get "Fault Service" and a few ClassNotFound Exceptions for some of the classes in my external jar file (I have already imported it as an external jar).
Does the external jar needs to be imported in another way?
I would expect a deployable application to be self contained, hence the "external" jars need to be included in my application. In my environment (WebSphere) you can also deploy external jars in some "shared" places and special directories, but for simple cases I prefer my app to be be self contained.
So, either include the JARs in WEB-INF/lib or package the app in an EAR file, place the JARs in teh root of the EAR and adjust the Manifest for your WAR to refer to those JARs.
Related
My organization is creating a "base" Java web app that is meant to be customized by adding jar files (with customized classes) by adding the jar files to the web app's WEB-INF/lib directory. The goal is that our developers can simply create custom code, packaged as a simple jar file, which can be loaded into this "base" web app, so the developer doesn't have to worry about all the web app plumbing, just the actual custom code.
We're investigating a few different deployment models, but one idea was to put these jar files somewhere on a network directory. When the Java web app starts up, a ServletContextListener copies these jar files into the web app's WEB-INF/lib directory (the web app is originally deployed as a war file).
Then, another ServletContextListener uses Stripes' ResolverUtil class (JavaDoc here) to load all of the classes of a particular type (in this case, that implement a particular interface) that are located in the jar files that were copied into WEB-INF/lib.
Unfortunately, ResolverUtil fails to find those classes, even though they are in those copied jars. If I restart Tomcat (with those jar files still in WEB-INF/lib) they are found, as expected.
The jar files need to be in WEB-INF/lib because we want to use the Servlet 3.0 feature in which JSPs can be served from jar files, and for that to work, apparently those jar files need to be in WEB-INF/lib. If that weren't the case we would just add those jar files in the shared.loader property in catalina.properties.
So, it appears that Tomcat has already scanned the classpath for all class definitions by the time a web app is started, and since those jar files weren't in WEB-INF/lib when the web app started up, the classes will not be found.
Is there a way for those classes to be found? I don't need Tomcat to completely reload itself; I just need those new jar files and the class files they contain to be visible to the class loader. Is there a way to tell the classloader, "Hey, check the classpath again for new jars!" as I would only need to do it once, when the web app starts up?
Any other ideas?
Thank you!!
I have a web application that was deployed in tomcat. As part of third party library i am getting standalone jar file from my vendors. This jar file is set of few folders as well as class files and lib folder. this lib folder contains libraries which is required by the classes. Now i want to call the method of class (belongs to stand alone jar) in my web application and want to execute that method.when i tried it was throwing error not able to resolve dependency of jar files which is getting used by claases of standalone jar. Can somebody give me some thoughts on this.
I have a JAVA EE Project, containing both EJB and WAR projects inside of it.
I want to be able to access WAR project class from the EJB project class.
I have access the other way ( I can access ejb class from war).
Is that possibble? How can this be done?
Thank's In Advance.
I assume that you have got an EAR with two modules inside, WAR and EJB JAR. As both modules are independent, they shouldn't depend on each other. What you want to do is possible via MANIFEST.MF Class-Path entry in module META-INF folder, but I strongly discourage you to do so.
You can re-factor you application to following structure:
EAR/
ejb-app.jar
war-app.jar
lib/
common-libraries.jar
Just putyour common libraries to separate JAR (regular java project), and add it to ejb-app and war-app classpath.
Alternatively you can implement EJB's in WAR project as they are supported in WAR since Java EE6.
To run dynamic project in eclipse, I have already added required jars in project class path, some jars path are reference from other open project. even though it is throw class not found error. when I put that jars in bootstrap entries, it works fine.
So my questions are:
1) Is Bootstrap configuration mandatory to run dynamic project?
2) Why does it not find class path while running server?
3) How can I run my project without configuring Bootstrap entries?
It must not be put in the build classpath, neither under User entries, nor under Bootstrap entries.
It must be dropped inside the WebContent/WEB-INF/lib directory of your webapp project. Eclipse will detect them, automatically add them into the build path for you, and automatically include them into the WEB-INF/lib directory of the deployed webapp, since that's where the Java EE containers look for the libraries needed by a Java EE webapp.
I have a Java Project, for which I'm now creating a Web interface, using a Dynamic Web Project from Eclipse. The Web project consists of a single servlet and two JSP's. Something like this:
/JavaApplication
/src
/lib
/resources
/WebApplication
/src
/Servlet.java
/WebContent
/WEB-INF
index.jsp
other.jsp
Now, I need to reference JavaApplication from WebApplication, in order to use its classes to process web requests. What's the best way to accomplish this ? My idea is to create a .jar of the JavaApplication, containing all the .class files, /resources, and /libs. In this way, I could include the .jar in the web application, and I could have a single .war file that contained the entire application.
What do you think? How is this problem typically solved ?
Note: I don't want to convert the Java Project into a Web project.
In Eclipse project properties, add the project to the Java EE Module Dependencies (Eclipse 3.5 or older)
or Deployment Assembly (Eclipse 3.6 or newer) entry in the project properties.
This way Eclipse will take care about doing the right thing to create a WAR out of this all (it will end in /WEB-INF/lib). No other configuration is necessary, even not some fiddling in Build Path.
Under Eclipse, you can declare Project References for a given project, the web application in your case. To do so, right click on your web application project, then go for Properties > Project References and select the JavaApplication project. This should allow you to call code from the JavaApplication project from the WebApplication without having to build a WAR. This is a solution for development.
For standard deployment (outside the IDE), you should indeed create a standard WAR. To do so, you'll have to package your JavaApplication as a JAR including the .class files and the files under /resources but not the libraries it depends on (JARs under /lib). These dependencies will actually end up in the WEB-INF/lib directory of the WAR, beside the JAR of your JavaApplication. These steps are typically automated with tools like Ant or Maven.
Connecting java app to web app for development :
right click on web project :
properties>project references> add the java project you want to refer
Now in properties tab of web project go to
properties>deployment assembly> add the project manually and run the app
Consider moving up to EAR level, if your web container supports that.
The tricky part with shared code is where should the common code be put. A copy pr web application? A copy in the web container? Overdoing the "share these classes" might end up in class loader problems.
If you are creating two separate web applications refactor common java code into a separate Eclipse project and refer to it from both WAR projects.
EDIT: Apparently I have misread the problem description, and thought you asked about an existing and a new web application sharing code.
If you have an Eclipse project with your application, and another with your web frontend, then you can let your application export the necessary resources which the "Export WAR" in Eclipse Java EE can wrap up in a jar file and put in WEB-INF/lib for you. You need to say this explicitly with a checkmark in Properties -> Java EE Module Dependencies for your web project. Expect you have to experiment a bit - this took me a while to learn.
Typically you would create an API interface using remote service beans from the Java application that expose the methods that you want to invoke in the web application. You would include a proxy of the API interface with your web application that calls the remote service bean in the Java application. Remember that you will need to register the remote bean in the web.xml file.