I use the jstl library in my project, but as an external jar. After exporting my project to a .war file, these libraries are not included and I'm getting errors. How do I make sure the library is included in my war file?
Also, an unrelated question, if an ear file would have only one war module, is there a point to making it an .ear instead of .war
If you have put the jstl jars inside WebContent directory they will be packed in your WAR file. But if you are loading them from somewhere else make sure that you have them in your export list (Project Properties -> Java Build Path -> Order and Export).
If you have an EAR file you can make some extra settings in your application.xml file, or even some container specific ones.
Related
I have created a JavaFX application using NetBeans IDE and below is my folder structure.
I want to a build a single jar file including all dependencies for this jar to work properly.
This jar requires testplanner and batch folder from project root directory and files inside dist folder to work properly.
How can I package all this to a single jar file?
Theoretically JAR files cannot contain dependencies within, as java does not support it out of the box. WAR and EAR archives can. What You want to do is not standard, but is named fat jar. Fat jars are used i.e. by spring-boot maven plugin, but you could try this:
https://dzone.com/articles/how-build-fat-jar-using
And some more explanation:
NetBeans - deploying all in one jar
Use tecreations Deploy. Put all your sources into a path declared as Tecreations.getProjectPath(), run BuildAll to create your corresponding classes, put your jars in projectpath/jars and select the appropriate settings, whether to include jars, sources or classes. Select your main class and click Deploy. Unsigned and signed output jars are produced in user/Documents.
Download: https://tecreations.ca/java/downloads/release.
I have a requirement to add some custom classes and JSPs to an existing java web application. The custom classes must be in their own package, away from the existing java classes. The existing application is built on the struts framework.
I'm fairly new to all this and need guidance on the following:
Using Eclipse IDE, If I import the existing WAR file and libraries and unpack the WAR file, how do I compile new .java source files and add the .class files to the WAR?
The existing .class files are contained in a JAR. Do I need to create a JAR file containing the new .class files outside of eclipse and then add it to the same location as the existing .class JAR file i.e. WEB-INF/lib (there is no WEB-INF/lib/classes folder)
Adding the JSPs and amending the web.xml file should be fine but are there any pitfalls to look out for ?
Any and all help greatly appreciated
If I import the existing WAR file
I don't advise you to import third party war file into Eclipse. Instead do the following:
Create a dynamic web application in Eclipse (See the screenshot below):
Implement your custom classes and put them under the folder Java Resources / src
Put the JSPs under WebContent / jsps (you can choose any name you like)
Create a new directory in your file system (Windows / Unix ...) and copy the thirdparty war into it.
Unpack the war file using command line as:
jar xvf mythirdparty.war
Copy your class files (they should be under build / classes folder; see screenshot) to WEB-INF / classes folder of the unpacked thirdparty war.
Copy the JSPs (folder jsps) to the root of the unpacked war.
Remove the the old war (of the thirdparty war) so that
Navigate to the root and pack again as:
jar cvf thirdparty.war *
I have a war file, this war contains multiple jar files. Now my requirement is I have another war file which has dependency on jar files of first war. So Could any one help me how to refer the first war's jar files in MANIFEST file of the second war.
I think you can deploy those WARs in an EAR, and put the common resources in the EAR. Then you can update the manifest in each WARto use the resources in the EAR.
First of all, interdependent WAR applications that are not a part of the same EAR, sound like an awful idea. With that said, nothing is preventing you from extracting the common jars into application server's lib directory. But, why wouldn't each application contain it's own dependencies?
Actually I use MyEclise to develop and deploy a enterprise project(EAR file).
I use Java Build Path to add some other projects and link sources, and added several jar files (as external jar and user library) to my project. (I used J2EE technology and there are some default jar of course )
By myeclise deploying manager I deployed my project on weblogic base_domain and then by weblogic console I deploy it on weblogic.
All is set and there is no problem in all steps.
Now I wanna to create EAR file manually, first I created WAR file which included some jsf files and web-inf directory contains classes, lib directories and some important file like web.xml , facec-config.xml and etc.
In classes folder I have .class files which build correctly from .java files, and on lib directory**I copied all jar file from web-inf/lib directory** which created automatically by myeclipse deploying manager on weblogic base domain folder.
I added this War file into EAR file along APP-INF directory which contains all jar files from APP-INF/lib directory on weblogic base domain folder and META-INF directorywhat contains application.xml file.
When I deploy this ear file on weblogic there is so many error and problems.
Could you tell me what is the correct way to create that EAR file.
Thanks in advance
If you have an enterprise project, just export the EAR file. Right click the enterprise project, select Export, then select MyEclipse JEE->Ear File and follow instructions on the wizard (basically, specify a destination for the EAR file, on the file system). This should give you an EAR file that contains the same as what was deployed on Weblogic.
I am using maven build tool.
The following two are my intentions.
1) To move some of the third party library jars out of my war from WEB-INF/lib folder [note: These jars are common between more than 2 war files (or artifacts)]
2) To make the war file small in size.
Is it possible to move those jars out of war and put it into a folder and these jars should be referred in the classpath only by the wars which require it.
I have tried adding the path to the jars in the Class-Path: of MANIFEST.MF of war files but it did not work out. Please help me out.
I assume the jars in question are necessary for compiling the code that make up the web application. If the third-party jars are necessary for compilation but you don't want them in your war file, you have two options:
In the <dependency></dependency> section for the third-party jar, add "<scope>provided</scope>".
Configure the maven war plugin to exclude the jars you don't want in the war. See http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html for the details.
How you get the jar files that you exclude from the war into the web container's classpath depends on your environment. If you are using ear files, the Maven docs above talk about how to get the jars included in the ear file. If you are not using ear files, you will have to come up with your own way to get the jars into the container's lib directory.