I have an enterprise application .ear which includes few war files.
My .ear file also includes the jersey-server.jar and log4j.jar
These jar files are also part of the shared library that is mapped to the ear.
I would want to remove these files from ear altogether as they are already part of shared library.
when i remove these jars from ear, the http resource that is part of the war files goes unrecognized, 404 error and logs are not redirected to log files.
Can't I remove these files from the ear, use just shared libraries, which helps in reducing the size of the ear ?
Application is deployed in Websphere 8.
Thanks,
Ravi.
Related
Can I deploy an application without WAR/EAR in JBoss 6.4.0 eap ?
I need to migrate an application from Weblogic to JBoss. Is it possible to do so without creating the WAR ?
Deploy your app as an exploded set of files within directories, rather than packaged up within war and ear files. For example, assume you have xxx.ear which contains aaa.war. Under the deploy directory, create a directory named xxx.ear. In that directory create two more directories aaa.war. Into those directories place the contents of the two war files. Also, in the xxx.ear directory place the rest of the contents that would have been in the ear file, such as the META-INF/application.xml file.
Now, for example, you can easily add deploy/xxx.ear/aaa.war/some-new-file.html or edit deploy/xxx.ear/aaa.war/some-file.jsp.
I recently migrated from JBoss EAR 6.4.0 to 7.0.0. In my deployments folder, I have a EAR containing numerous JAR files of my project. When I unpack the file after building, all files are there as desired.
But as soon as I start the server and the EAR file gets unpacked by JBoss, a couple of my project JARs vanish. The files are simply not there, so my server starts incompletely and my EJB client cannot connect ("No EJB receiver for handling...").
Is there any 'smart' mechanism in JBoss that may cause this behaviour?
My colleagues are working on the same project (but different IDE) with no problems.
You must specify each jar as a module in the application.xml file in the ear context.
<display-name>Your-ear-file-display-name</display-name>
<module>
<java>YourEJBJar.jar</java>
</module>
...
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.
What is the difference between a .jar and a .war file?
Is it only the file extension or is there something more?
From Java Tips: Difference between ear jar and war files:
These files are simply zipped files
using the java jar tool. These files are
created for different purposes. Here
is the description of these files:
.jar files: The .jar files contain
libraries, resources and
accessories files like property files.
.war files: The war file contains
the web application that can be
deployed on any servlet/jsp
container. The .war file contains jsp,
html, javascript and other files
necessary for the development of web
applications.
Official Sun/Oracle descriptions:
The J2EETM Tutorial: Web Application Archives
The Java Archive (JAR) File Format: The Basics
Wikipedia articles:
WAR file format (Sun)
JAR file
WAR stands for Web application ARchive
JAR stands for Java ARchive
A .war file has a specific structure in terms of where certain files will be. Other than that, yes, it's just a .jar.
You add web components to a J2EE application in a package called a web application archive (WAR), which is a JAR similar to the package used for Java class libraries. A WAR usually contains other resources besides web components, including:
Server-side utility classes (database beans, shopping carts, and so on).
Static web resources (HTML, image, and sound files, and so on)
Client-side classes (applets and utility classes)
A WAR has a specific hierarchical directory structure. The top-level directory of a WAR is the document root of the application. The document root is where JSP pages, client-side classes and archives, and static web resources are stored.
(source)
So a .war is a .jar, but it contains web application components and is laid out according to a specific structure. A .war is designed to be deployed to a web application server such as Tomcat or Jetty or a Java EE server such as JBoss or Glassfish.
A .war file is a Web Application Archive which runs inside an application server while a .jar is Java Application Archive that runs a desktop application on a user's machine.
A war file is a special jar file that is used to package a web application to make it easy to deploy it on an application server. The content of the war file must follow a defined structure.
.jar and .war are both zipped archived files.
Both can have the optional META-INF/MANIFEST.MF manifest file which hold informative information like versioning, and instructional attributes like classpath and main-class for the JVM that will execute it.
.war file - Web Application Archive intended to be execute inside a 'Servlet Container' and may include other jar files (at WEB-INF/lib directory) compiled classes (at WEB-INF/classes (servlet goes there too)) .jsp files images, files etc.
All WAR content that is there in order to create a self-contained module.
war and jar are archives for java files. war is web archive and they are running on web server. jar is java archive.
Basicly both compressed archives. war is used for web application with a specific directory structure.
A JAR file extension is .jar and is created with jar command from command prompt (like javac command is executed). Generally, a JAR file contains Java related resources like libraries, classes etc.JAR file is like winzip file except that Jar files are platform independent.
A WAR file is simply a JAR file but contains only Web related Java files like Servlets, JSP, HTML.
To execute a WAR file, a Web server or Web container is required, for example, Tomcat or Weblogic or Websphere. To execute a JAR file, simple JDK is enough.
War : For web-applications
Jar : For desktop applications
OR
War : Working on browser
Jar : Working on machine
War -
distribute Java-based web applications. A WAR has the same file
structure as a JAR file, which is a single compressed file that
contains multiple files bundled inside it.
Jar -
The .jar files contain libraries, resources and accessories files
like property files.
WAR files are used to combine JSPs, servlets, Java class files, XML
files, javascript libraries, JAR libraries, static web pages, and any
other resources needed to run the application.
Jar:- jar contain only .class
war:- war contain html, js, css and .class also jsp and servlets pages
JAR files allow to package multiple files in order to use it as a library, plugin, or any kind of application. On the other hand, WAR files are used only for web applications.
JAR can be created with any desired structure. In contrast, WAR has a predefined structure with WEB-INF and META-INF directories.
A JAR file allows Java Runtime Environment (JRE) to deploy an entire application including the classes and the associated resources in a single request. On the other hand, a WAR file allows testing and deploying a web application easily.
Also, using an embedded container, you can run a JAR file directly whitouh setting up a web server like when running your java app with spring boot. However, for a WAR file, you need to set up first a web server like Tomcat for example.
What is the difference between a .war and .ear file?
A WAR (Web Archive) is a module that gets loaded into a Web container of a Java Application Server. A Java Application Server has two containers (runtime environments) - one is a Web container and the other is a EJB container.
The Web container hosts Web applications based on JSP or the Servlets API - designed specifically for web request handling - so more of a request/response style of distributed computing. A Web container requires the Web module to be packaged as a WAR file - that is a special JAR file with a web.xml file in the WEB-INF folder.
An EJB container hosts Enterprise java beans based on the EJB API designed to provide extended business functionality such as declarative transactions, declarative method level security and multiprotocol support - so more of an RPC style of distributed computing. EJB containers require EJB modules to be packaged as JAR files - these have an ejb-jar.xml file in the META-INF folder.
Enterprise applications may consist of one or more modules that can either be Web modules (packaged as a WAR file), EJB modules (packaged as a JAR file), or both of them. Enterprise applications are packaged as EAR files ― these are special JAR files containing an application.xml file in the META-INF folder.
Basically, EAR files are a superset containing WAR files and JAR files. Java Application Servers allow deployment of standalone web modules in a WAR file, though internally, they create EAR files as a wrapper around WAR files. Standalone web containers such as Tomcat and Jetty do not support EAR files ― these are not full-fledged Application servers. Web applications in these containers are to be deployed as WAR files only.
In application servers, EAR files contain configurations such as application security role mapping, EJB reference mapping and context root URL mapping of web modules.
Apart from Web modules and EJB modules, EAR files can also contain connector modules packaged as RAR files and Client modules packaged as JAR files.
From GeekInterview:
In J2EE application, modules are packaged as EAR, JAR, and WAR based on their functionality
JAR:
EJB modules which contain enterprise java beans (class files) and EJB deployment descriptor are packed as JAR files with .jar extension
WAR:
Web modules which contain Servlet class files, JSP Files, supporting files, GIF and HTML files are packaged as a JAR file with .war (web archive) extension
EAR:
All the above files (.jar and .war) are packaged as a JAR file with .ear (enterprise archive) extension and deployed into Application Server.
war - web archive. It is used to deploy web applications according to the servlet standard. It is a jar file containing a special directory called WEB-INF and several files and directories inside it (web.xml, lib, classes) as well as all the HTML, JSP, images, CSS, JavaScript and other resources of the web application
ear - enterprise archive. It is used to deploy enterprise application containing EJBs, web applications, and 3rd party libraries. It is also a jar file, it has a special directory called APP-INF that contains the application.xml file, and it contains jar and war files.
WAR (web archive) files contain servlet class files, JSPs (Java servlet pages), HTML and graphical files, and other supporting files.
EAR (enterprise archive) files contain the WAR files along with the JAR files containing code.
There may be other things in those files but their basically meant for what they sound like they mean: WAR for web-type stuff, EAR for enterprise-type stuff (WARs, code, connectors et al).
JAR Files
A JAR (short for Java Archive) file permits the combination of several
files into a single one. Files with the '.jar'; extension are utilized by
software developers to distribute Java classes and various metadata.
These also hold libraries and resource files, as well as accessory files
(such as property files).
Users can extract and create JAR files with Java Development Kit's
(JDK) '.jar' command. ZIP tools may also be used.
JAR files have optional manifest files. Entries within the manifest file
prescribe the JAR file's use. A 'main' class specification for a file class
denotes the file as a detached or ‘stand-alone' program.
WAR Files
A WAR (or Web Application archive) files can comprise XML
(extensible Markup Language) files, Java classes, as well as Java Server
pages for purposes of Internet application. It is also employed to mark
libraries and Web pages which make up a Web application. Files with
the ‘.war' extension contain the Web app for use with server or JSP (Java
Server Page) containers. It has JSP, HTML (Hypertext Markup
Language), JavaScript, and various files for creating the aforementioned
Web apps.
A WAR file is structured as such to allow for special directories and
files. It may also have a digital signature (much like that of a JAR file)
to show the veracity of the code.
EAR Files
An EAR (Enterprise Archive) file merges JAR and WAR files into a
single archive. These files with the ‘.ear' extension have a directory for
metadata. The modules are packaged into on archive for smooth and
simultaneous operation of the different modules within an app server.
The EAR file also has deployment descriptors (which are XML files)
which effectively dictate the deployment of the different modules.
Refer: http://www.wellho.net/mouth/754_tar-jar-war-ear-sar-files.html
tar (tape archives)
- Format used is file written in serial units of fileName, fileSize, fileData
- no compression. can be huge
Jar (java archive)
- compression techniques used
- generally contains java information like class/java files. But can contain any files and directory structure
war (web application archives)
- similar like jar files only have specific directory structure as per JSP/Servlet spec for deployment purposes
ear (enterprise archives)
- similar like jar files. have directory structure following J2EE requirements so that it can be deployed on J2EE application servers.
- can contain multiple JAR and WAR files
Ear files provide more options to configure the interaction with the application server.
For example: if the hibernate version of the application server is older than the one provided by your dependencies, you can add the following to ear-deployer-jboss-beans.xml for JBOSS to isolate classloaders and avoid conflicts:
<bean name="EARClassLoaderDeployer" class="org.jboss.deployment.EarClassLoaderDeployer">
<property name="isolated">true</property>
</bean>
or to src/main/application/META-INF/jboss-app.xml :
<?xml version="1.0"?>
<jboss-app>
<loader-repository>
loader=nameofyourear.ear
<loader-repository-config>java2ParentDelegation=false</loader-repository-config>
</loader-repository>
</jboss-app>
This will make sure that there is no classloader conflict between your application and the application server.
Normally the classloader mechanism works like this:
When a class loading request is presented to a class loader, it first
asks its parent class loader to fulfill the request. The parent, in
turn, asks its parent for the class until the request reaches the top
of the hierarchy. If the class loader at the top of the hierarchy
cannot fulfill the request, then the child class loader that called it
is responsible for loading the class.
By isolating the classloaders, your ear classloader will not look in the parent (=JBoss / other AS classloader).
As far is I know, this is not possible with war files.
J2EE defines three types of archives:
Java Archives (JAR) A JAR file encapsulates one or more Java classes, a manifest, and a descriptor. JAR files are the lowest level of archive. JAR files are used in J2EE for packaging EJBs and client-side Java Applications.
Web Archives (WAR) WAR files are similar to JAR files, except that they are specifically for web applications made from Servlets, JSPs, and supporting classes.
Enterprise Archives (EAR) ”An EAR file contains all of the components that make up a particular J2EE application.
To make the project transport, deployment made easy.
need to compressed into one file.
JAR (java archive) group of .class files
WAR (web archive) - each war represents one web application
- use only web related technologies like servlet, jsps can be used.
- can run on Tomcat server
- web app developed by web related technologies only jsp servlet html js
- info representation only no transactions.
EAR (enterprise archive) - each ear represents one enterprise application
- we can use anything from j2ee like ejb, jms can happily be used.
- can run on Glassfish like server not on Tomcat server.
- enterprise app devloped by any technology anything from j2ee like all web
app plus ejbs jms etc.
- does transactions with info representation. eg. Bank app, Telecom app