I am using two servers one is tomcat and other one is WebLogic.
I developed two application, one is Main-Application and second is commons-application.
I added quartz JAR into the commons-application and export it as a JAR and add it in the Main-Application.
For importing quartz JAR into the commons-application I made a lib folder and give the path of it in build path configuration.
Now when I run Main-Application it gives me error that class not found that is associated with quartz.
So I add quartz JAR into the Main-Application too, and run again so it executed fine.
But when I run same configuration in WebLogic it gave me same error(class no found). What am I missing? Do I need to do something else for WebLogic?
Not sure about main method apps, but in web apps we have to provide a preference to our classpath jars.
Weblogic being an app server provides its own jars and other services.
And by default it prefers to use its own jars. So if you want to use your own jars which are in your project's class path then you specifically have to mention so.
Tomcat being a servlet container doesn't have its own jars, so it will by default refer to your libraries.
See the prefer web inf classes.
http://docs.oracle.com/cd/E24329_01/web.1211/e21049/weblogic_xml.htm
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
Similar classpath settings should be available for main class apps, I guess.
Also, more importantly, jars should not be embedded into other jars. (I think you are embedding quarts inside other common jar. Main application should have two jars: commonsapp.jar and quartz.jar in its classpath.)
Related
My servlet application uses JavaMail API and Java Activation Framework (JAF). I do development in IntelliJ IDE. TomCat runs on the same local Windows machine. When I try to run my Servlet from IntelliJ I have error related to fact TomCat not finds mentioned libraries. What is the right place to store libraries for TomCat? Is it possible ask IntelliJ to place required libraries to TomCat ?
Put the jar files in the WEB-INF/lib folder. If there isn't one, create one manually.
This way the jar files are added to the war file that gets created when you build your artifact, and tomcat knows where to find those jars at runtime.
When I developed any web application I added many jars which my code depended on them.
I want to know when I deployed the war on the server how server or containers using these jars,
And if I but them on server's modules directly is it will be an advantage for publishing or deploying ?!
When your code is executed the container will look within your war to see if the dependent jar is available. If it cannot find the dependent jar within your war then the container will traverse it's tree to see if it can find the dependency somewhere within the container itself. Through configuration, it is possible to reverse so the war is checked last.
The war should be self-contained, with the dependent jars in the war's WEB-INF/lib folder. Configure the container (likely default) to check the war first. This maintains isolation which helps keep the app stable over time. For example, the container might be updated but your app should not need to be updated.
Deploying those dependent jars outside the war, to somewhere within the container to a shared folder, will likely make those dependent jars visible to all deployed apps and/or the container itself. This eventually leads to jar version conflicts and class loader issues. Don't do it!
There is no advantage using jar dependencies on the server classpath. This will force you to depend on the server itself which is not a good idea when dealing with continuous delivery.
BTW you shall know that every war file has it own classpath when deployed, so if you deploy some war, let's suppose on a Tomcat Server, it will use it's own classpath which contains the necessary jars. The container (Tomcat in this case) will know nothing about these jars but your application will.
I was going through java tutorials and found that after creating the servlet they have added the servlet.jar file using build path opt. But in my case servlet is still working without that external jar file.
So what is the need of that external jar file?
It's still working fine in your case because
Just check below
Right click on your project then go to Properties -> Targeted Runtime -> Apache tomcat
If you have selected that checkbox you no need to add servlet jar and if it's not then you need to add servlet jar in lib folder
So in your case you must have selected targeted runtime that's why even though u have not added servlet jar file it's working fine
You don't need to add because you may have added Apache Tomcat as server run time in for your web project and Apache tomcat has servlet.jar in its lib folder so it will be there
you can check it by going in Apache tomcat folder > lib
You need Servlet-api.jar to compile servlets in eclipse but while deploying servlet container ( like tomcat ) will have it built in. Infact it is bad practise to include it inside your WEB-INF/LIB folder.If you configure your eclipse to use libraries from tomcat(or other servlet containers) then you might not need it manually.
Servlet-api.jar is by default provided by the container environment. So you should not put it in your WEB-INF/LIB folder when you are deploying your application. However, it is required for compiling your Servlets. In case if you are using Eclipse as your IDE, place it in your classpath using Add External JAR files option.
Ensure that you're using at least Eclipse IDE for Java EE developers (with the EE). It contains development tools to create dynamic web projects and easily integrate servletcontainers (those tools are part of Web Tools Platform, WTP). You also need to ensure that you already have a servletcontainer installed which implements at least the same Servlet API version as the servletcontainer in the production environment, for example Apache Tomcat, Oracle GlassFish, JBoss AS/WildFly, etc.
You should above all never manually copy/download/move/include the individual servletcontainer-specific libraries like servlet-api.jar, jsp-api.jar, el-api.jar, j2ee.jar, javaee.jar, etc. It would only lead to future portability, compatibility, classpath and maintainability troubles, because your webapp would not work when it's deployed to a servletcontainer of a different make/version than where those libraries are originally obtained from.
These links below will give you more information about this
How do I import the javax.servlet API in my Eclipse project?
Understanding who provides servlet-api.jar, is it web-container or part of Java EE download
http://wiki.metawerx.net/wiki/JARFilesYouShouldNeverIncludeInYourWebapp
My project generates a Jar as the output package and uses an external War file, available on our Artifactory, as the Web Application to be deployed on Tomcat (currently using version 7). This War file contains all libs and modules required for the application to run.
I have already packaged and ran those projects outside eclipse on a "vanilla" Tomcat installation. In this scenario, the Jar my project generates is loaded on the context.xml file this way:
<Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="/home/igor/workspace/myapp/myapp-2.4.3.jar"/>
Is there a way I can deploy this project on Tomcat using Eclipse and still be able to debug it? Can I use the Jar generated for this purpose or do I have to deploy the workspace project?
As for the War file, do (or can) I have to add it as an dependency?
Thanks in advance!
EDIT
We actually provide an Web Framework, which is packaged as a war. Other applications that use that framework are exported as jars and loaded into the framework through the context file as cited above.
Your question is confusing probably because of your custom plugin/classloader and deployment which is sort of orthogonal to debugging.
What I recommend is you keep whatever system you have to build/package/deploy and use JVM remote debugging. That is do not use the Eclipse WTP since you seem to have custom steps for deployment but rather build your code deploy & run a separate Tomcat instance and then run the remote debugger in Eclipse.
You will get some hotcode swapping with this method but not as much as something like JRebel.. (which you could use also) it will certainly be better than constantly redeploying.
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.