Creating war file with jar command is not working properly - java

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 .

Related

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 a exc jar file in eclipse ?

so I created a jar file, clicked on export and etc
but when I double click it doesnt do anything
I dont see my classes in the folder
all i see is
junit
org.hamcrest.core_1.1.0.v2009050107100…
what am i doing wrong ?
If your jar is a valid executable
then this should work
java -jar your.jar
Jar files don't aren't always run by double-clicking.
In order to run the jar file, run the command java -jar yourjarfile.jar while in the same directory as the jar file. This assumes that your PATH system variable is set properly.
If you receive an error such as "Failed to load Main-Class manifest attribute from yourjarfile.jar" it means that there is no main class defined in your jar file, and the java interpreter doesn't know where to start.
You can make sure that a main class is specified in Eclipse by exporting as a "Runnable JAR file" and making sure you select a launch configuration that you use to run your program.
In order to list the contents of the jar file, run the command jar tvf yourjarfile.jar while in the same directory as the jar file.
In order to extract the contents of the jar file, run the command jar xvf yourjarfile.jar while in the same directory as the jar file.

trying to run a .jar file in command prompt

I am trying to run a jar file using my command prompt (Windows XP) but get NoClassDefFoundError.
I have my DateAndTime.class file in a folder called dateandtime and also indicated a package called dateandtime in the source file.
Outside the folder I have a manifest.mf file with specification
Main-Class: dateandtime.DateAndTime
I put this in the command file
jar cmf manifest.mf myJarFile.jar dateandtime
and this creates the myJarFile.jar in the same folder as manifest.mf.
When I try to run this jar file however I get the NoClassDefFoundError
java -jar myJarFile.jar
If I jave all the classes in the same directory with no package specified then the .jar file runs fine but as soon as I try to specify a package, even though myJarFile.jar was created I get the error.
Why is that?
Regards
If you are getting a NoClassDefFoundError it means a class that was present during compilation of your classes is absent during their execution. Which implies that you JAR file does not contain all the dependencies requires by your classes in order to run. Since your question is lacking detail on your project structure I can only recommend you revisit your application's dependency tree and determine all the classes that need to be included in the JAR.
Syntax:
java -jar fileName.jar
Example:
java -jar myfile.jar

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

Making a JAR file which includes all files of a cetain type from any subdirectory

So this is a simplified version of my package structure
Project 1
-folder1
-folder2
-folder21
-folder211
-test3.java
-folder22
-folder3
-test4.java
-Project2
-folder1
-folder11
-folder111
-Test.java
-folder2
-.properties
-Test2.java
-folder3
What I want to find is command that will create a jar and take the paths to project1 and project2 and recursively add the folder structure and java files without adding the .properties files.
What i've tried so far is
jar cvf test.jar "pathtoproject1/.java" "pathtoproject2/.java"
That only works for java files in the base project directories not the subfolders.
Anyone know how to do this?
edit
This is for a batch script on windows
Frankly I'm not sure that jar handles this out of the box.
I suggest using ant - with an ant jar task, using a fileset.

Categories