Reputation: 6208
I installed JBoss Developer Studio and it's possible to create a WAR file by "right mouse project > Export > WAR file" but I want to export my project to a WAR file using the commandline.
I have maven installed which is one of the requirements of the Studio and I read that I can generate a WAR file using maven but I require a file called pom.xml. When I searched through my workspace and project, pom.xml was missing. I may need to manually create pom.xml but I'm unsure how to.
My directory tree for my project is the following:
Siesta
├── build
│ └── classes
├── src
└── WebContent
├── extjs
├── extjs-4.2.0
├── extjs-4.2.2
├── index.jsp
├── META-INF
├── siesta
├── tests
└── WEB-INF
How do I create a WAR file for my Maven / JBoss project using the command line? I use Linux and would prefer not having to create a pom.xml file but if there isn't another way, then I'll use the xml file to generate the war file.
Edit:
So jar is the way to go to create a war file. I wrote up a tiny script that will create a war file for me for a specific directory.
#!/bin/bash
cd Siesta/WebContent/
jar -cvf ../../Siesta.war *
cd -
Then if you open the war file in a zip utility or archive manager in ubuntu, you'll see this structure
├── extjs
├── extjs-4.2.0
├── extjs-4.2.2
├── index.jsp
├── META-INF
├── siesta
├── tests
└── WEB-INF
I have to CD into the directory that I want to create a war file of which is kind of annoying. I think there may be a better way to do it using jar's -C option but when I used "jar -cvf Siesta.war -C Siesta/WebContent *" it didn't have the same result.
Edit2:
jar -cvf my-app.war myfolder/
For my application to work on TomCat, I use the following:
cd Siesta/WebContent
jar -cvf Siesta.war *
Upvotes: 19
Views: 94443
Reputation: 4328
The simplest choice (if you are using Maven) is to create it with the maven-archetype-webapp:
mvn archetype:generate -DgroupId=com.sample -DartifactId=web-project -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
You can then refine your pom.xml to include the dependencies required, for example:
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
Source: How to create a Web application from the Command Line
Upvotes: 2
Reputation: 17850
If this is a Maven project, then open your console, navigate to where the pom.xml file is and then run:
mvn package
It will create the {artifactId}-{version}.war file under ${basedir}/target directory. This assumes that your packaging
POM element is set to war
in your pom.xml file.
<project ...>
...
<packaging>war</packaging>
...
</project>
Some of the valid packaging values are jar, war, ear and pom. If no packaging value has been specified, it will default to jar.
Upvotes: 7
Reputation: 2844
Alright here is a already existing SO with a couple of possibilities on how to create a war file: How to create war files.
I personaly prefer Maven over any other build scenario - Since i migrated from ANT i did not like Maven in the first place but after investing like a day or two into the documentations: http://maven.apache.org/pom.html i started to love it. In your case all you need is refactor your project to meet the maven standard file structure and create a minimum Maven project (a.k.a. pom.xml
file) for your sources that has the packaging war
instead of the default jar
.
If you want to stick with the console only and dont use any build helpers beside the ones delivered by the JDK you can create your war with something like this:
jar cvf my-app.war
Have a look at this: https://docs.oracle.com/javase/tutorial/deployment/jar/build.html for a complete reference of the supported options.
(Note: A "war" in the context of java based web applications follows a standard format: http://docs.oracle.com/javaee/6/tutorial/doc/bnaby.html while the technical ".war" file is just the same as a ZIP compressed folder renamed to ".zip".)
(Also note i would realy take the time to get in touch with maven since after that you know about a serious build tool and will be able to create jar
, ear
, war
etc. in a standard process).
Upvotes: 7