As I know it's rule to locate servlets in webapplication module. So after packaging we'll have war archive.
But later I need servlets to use like library. So as we cannot use war file as library i need the jar.
The question: is it normall to refactor webmodule so that move servlets to other project(module) to package to jar archive and use it in webapp as dependency while compiling ?
It's pretty rare to have general purpose, reusable servlets (except if you're developing a framework). But if you have one, putting it in a jar to make it reusable by several webapps is the way to go.
It's not normal (or, indeed, recommended) to package servlets in a jar or to use them as "libraries". What you are supposed to do is extract and isolate any business-logic that is "common" and should be usable by others than the servlet. Those classes can then be packed in a jar that is included in the webapp war as well as any other clients/modules you have that need them.
Related
I have a struts project. It has many jars in its APP-INF/lib directory and the packaged ear size is huge. I also have another spring boot project and it has one utility class.
My target is to use that utility from the struts project.
The problem here is, if I include this spring-boot jar in the pom.xml, it includes the spring boot jar with all its dependency which are already present in the struts project. This makes the ear more huge. The jars are copied twice in a way. Basically the project becomes like this:
struts-project
--APP-INF/libs/
----**.jar (many jars)
----spring-boot-project.jar
--------BOOT-CONF/libs/
-------------**.jar (again many jars, most of them already in one level above directory)
My end goal is to use the utility, for which I have 2 ways (what I have in mind, more ways possible)
Include the spring boot jar, but find a way to reduce packaged ear size.
Create a rest api in the spirng boot project just to use the jar. But if the service is down anyhow, it will have huge impact on main application - so don't want to use this way also.
Please suggest more ways to achieve my end goal. Or any improvement/suggestion in the above approaches.
In order to use utility / commons classes in many project you should create separate project for utility.
Utility project should not use any dependency or very little in other case you should redesign it.
I currently have a Java EE Netbeans project with multiple servlets. Some of these servlets are dependent on the same classes and libraries, and some are not.
At the moment a single WAR file is built, containing all classes and servlets.
What I'm trying to do tell the IDE to build one WAR for each servlet, where the WAR contains the dependencies along with the servlet itself.
I've tried looking through the build.xml for what tags to override, but I don't find anything that suits my needs.
How do I accomplish this?
I have a main project used as a standalone batch that I want to move to the container using EJB timer (using WildFly 8.2). I thought building a WAR file with the timer class and the dependencies withing WEB-INF/lib, but doesn't sound an elegant solution because it isn't a web app, it doesn't need to bound a context. It's just a JAR, with an EJB inside and the dependencies (I'm using a fat jar) but the container throws an error when I deploy it. Should I use an EAR? Or do you guys think a WAR file is fine?
PS: I'm using Maven, so possible suggestions can take it in account.
You don't really need it in a WAR file if it's not a web application, although it doesn't harms. I would also put it in a JAR file, i don't like to add something that doesn't have a meaning...it can be confusing for others. But as #Bruno César pointed out, you need to package first the EJB(s). Have a look at this; you'll see the ways to package them as JAR, WAR, EAR.
EJB package is good solution if your standalone application has no any third party libraries. But if it has, then best solution would be EAR package type.
what is the difference between simple project/lib and project/web/WEB-INF/lib?
which jar should be in project/lib folder and which jars should be in web/WEB-INF/lib?
there is no standard project/lib thing, it might be a specific project designed that way to hold library there and while compiling and deploying it might be configured to read jars from there,
where as if you put it in WEB-INF/lib web contains puts all the jars from this directory in runtime classpath so they would be available when application is running
better to use maven without needing to holding library in source control and with lots of other advantages maven brings
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.