Replace a file from .war with another file using Cron Job - java

I have a mayapp.war which is deployed in tomcat server. I want to replace a file(test.properties) which resides inside myapp.war with another file(test.properties) and this file resides outside myapp.war. I want to do this stuff using a cron job. will appreciate any kind of help.

A war file is just a zip file. You can use any zip command tool to replace a file or you can use the jar command from the JDK.
Use following command:
jar uf myapp.war test.properties

Related

Creating war from its component folders

I have deployed my war file on a remote linux server. I run this war using jetty-runner. Its not feasible for me to push this war multiple time. Its size is huge and it takes aprrox 45 min to push a fresh war onto the server. To handle this issue I thought of using the following steps(with commands) :
unzip:Unzip war to its corresponding files/folders : WEB-INF, META-INF, index.jsp.
Updating new class file in WEB-INF.
zip:Repacking these folder into a war again.
But the newly created war does not work. Is there a standard/correct way to pack these files into a war. Also, jar command is not available on the server.
Please suggest.
P.S. Already looked into various SO questions but didn't find any useful solution.
The zip command does not work as expected. The war packed by that command did not work. Instead, we have to use the JAR command.
I was able to generate the war after modifying the contents by using :
jar -cvf webproject.war index.jsp META-INF/ WEB-INF/
Note: If the jar command is not available on the server, specify JAR path using installed java on the server:
PATH_TO_JAVA/bin/jar -cvf webproject.war index.jsp META-INF/ WEB-INF/

How to create an executable jar file which can be distributed or packaged?

I am using getdown to create a means to update a java application.
When I have completed this tutorial, I tested if it works on command line as below:
% java -jar c:/downloads/getdown-X.Y.jar c:/netBeans/getdown/src
Thankfully, this works and launches the application. Great.
How do I make a jar file and distribute this?
I tried to make a jar file on this project but it didn't work, this project does not run. When I run this getdown-X.Y.jar on command line.
I think it still using the same file which I created before c:/netBeans/getdown/src. Eventually, it is failing to execute since it is missing the jar file. So, how to make this project into a jar file and distribute it.
I am not sure what OS you are working on.You can do this by creating an executable jar file. Please follow the steps here:
If you want to create a jar file with additional file. Here in below, if you want to create a jar file of imagine src.class with additonal text file with it which is readme.txt
c:\patel\projects\netbeans\getdown\src.class
c:\patel\projects\readme.txt
Run this command: jar -cvfm src.jar readme.txt netbeans\getdown\*.class
which is: c:\patel\projects\jar -cvfm src.jar readme.txt netbeans\getdown\*.class
Now your executable jar file is ready. To run this jar file:
run this on command prompt: java -jar src.jar

Creating war file

I have extracted existing WAR file contents and modified few images. Now I have to re-create it to WAR file again using the extracted code from original war file.
I am working on linux.
Any idea how can we re-create war file.
Thanks
--Sam
You can use the java jar command line utility to create the war file again:
jar -cvf yourwar.war updatedContentsdir
Learn more here:
http://docs.oracle.com/javase/tutorial/deployment/jar/build.html

Creating war file with jar command is not working properly

Hi all i have used the following command to generate war file from my spring project.
D:\projectsample\webContent>jar cvf projectsample.war
The war file is generating but when i deploying it using the jettyrunner.jar,its not deploying.I have noticed in the war file that there is no class files are generating inside the WEB-INF\class folder.Can anyone suggest me a solution for this problem.
"jar" command will not create .class files, it is for creating the package. So you have to compile the source files first, then use the jar command.
Also, you might need to add as parameter(s) the files you want to include, so something like
jar cvf myapp.war *
To add all files.
How To Create i.war in Java
1.Install Jdk
2.Set JAVA_HOME in Inviroment
3.cmd = >
4.c:\user> Cd D:\apex_listener
5.D:\apex_listener> jar -cvf0 D:\apex_listener\i.war -C Y:\APPLICATION_EXPERESS\apex_4.2.2_en\apex\images .

How to extract .war files in java? ZIP vs JAR

I have a web program where I want the user to be able to import a .war file and I can extract certain files out of the .war file. I have found two class libraries: java.util.zip.* and java.util.jar.*. From what I understand, a WAR file is a special JAR file which is a special ZIP file. So would it be better to use java.util.jar? If ZIP and JAR files are pretty much the same why is there a need for two different libraries?
WAR file is just a JAR file, to extract it, just issue following jar command –
jar -xvf yourWARfileName.war
If the jar command is not found, which sometimes happens in the Windows command prompt, then specify full path i.e. in my case it is,
c:\java\jdk-1.7.0\bin\jar -xvf my-file.war
If you look at the JarFile API you'll see that it's a subclass of the ZipFile class.
The jar-specific classes mostly just add jar-specific functionality, like direct support for manifest file attributes and so on.
It's OOP "in action"; since jar files are zip files, the jar classes can use zip functionality and provide additional utility.
Just rename the .war into .jar and unzip it using Winrar (or any other archive manager).
If you using Linux or Ubuntu than you can directly extract data from .war file.
A war file is just a jar file, to extract it, just issue following command using the jar program:
jar -xvf yourWARfileName.war
You can use a turn-around and just deploy the application into tomcat server: just copy/paste under the webapps folder.
Once tomcat is started, it will create a folder with the app name and you can access the contents directly
For mac users: in terminal command :
unzip yourWARfileName.war
Like you said, a jar is a zip file (not a special type, but just a plain old zip), so either library could be made to work. The reasoning is that the average person, seeing a *.zip extension, tends to unzip it. Since the app server wants it unzipped, a simple rename keeps people from unzipping it simply out of habit. Likewise, *.war file also should remain uncompressed.
java.util.jar basically just adds additional functionality to java.util.zip with very little extra overhead. Let the java.util.jar be a helper in posting, etc... and use it.
Jar class/package is for specific Jar file mechanisms where there is a manifest that is used by the Jar files in some cases.
The Zip file class/package handles any compressed files that include Jar files, which is a type of compressed file.
The Jar classes thus extend the Zip package classes.
This is the way to unarchive war
mkdir mywarfile
cp -r mywarfile.war mywarfile/
cd mywarfile/
jar -xvf mywarfile.war
ls
rm -rf mywarfile.war

Categories