How to create a WAR file using the command line?

I installed JBoss Developer Studio and was able to create a WAR file using the "right-click project> Export> WAR file", but I want to export my project to a WAR file using the command line.

I have maven installed, which is one of Studio's requirements, and I read that I can generate a WAR file using maven, but I need a pom.xml file. When I was browsing my workspace and project, pom.xml was missing. I may need to manually create pom.xml, but I'm not sure how to do this.

My directory tree for my project is as follows:

Siesta β”œβ”€β”€ build β”‚  └── classes β”œβ”€β”€ src └── WebContent β”œβ”€β”€ extjs β”œβ”€β”€ extjs-4.2.0 β”œβ”€β”€ extjs-4.2.2 β”œβ”€β”€ index.jsp β”œβ”€β”€ META-INF β”œβ”€β”€ siesta β”œβ”€β”€ tests └── WEB-INF 

How to create a WAR file for my Maven / JBoss project using the command line? I use Linux and prefer not to create the pom.xml file, but if there is no other way, I will use the xml file to create the war file.

Edit:

So jar is a way to go about creating a war file. I wrote a small 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 zip utility or archive manager in ubuntu, you will see this structure

  β”œβ”€β”€ extjs β”œβ”€β”€ extjs-4.2.0 β”œβ”€β”€ extjs-4.2.2 β”œβ”€β”€ index.jsp β”œβ”€β”€ META-INF β”œβ”€β”€ siesta β”œβ”€β”€ tests └── WEB-INF 

I have a CD in the directory that I want to create a war file that is annoying. I think there may be a better way to do this using the jar -C option, but when I used "jar -cvf Siesta.war -C Siesta / WebContent *" it did not have the same result.

Edit2:

 jar -cvf my-app.war myfolder/ 

For my TomCat application, I use the following:

 cd Siesta/WebContent jar -cvf Siesta.war * 
+6
source share
2 answers

Well, SO already exists here with several options for creating a war file: How to create war files .

I personally prefer Maven over any other build script. Since I switched from ANT, I did not like Maven, but after you invested a day or two in the documentation: http://maven.apache.org/pom.html I started to love it. In your case, all you need to do is reorganize your project to fit the standard maven file structure and create a minimal Maven project (aka pom.xml file) for your sources that have war packaging instead of the standard jar .

If you want to use the console and do not use any build helpers next to those supplied by the JDK, you can create your own war with something like this:

jar cvf my-app.war

Take a look at this: https://docs.oracle.com/javase/tutorial/deployment/jar/build.html for a full link to the supported options.

(Note: β€œWar” in the context of Java-based web applications follows standard formats: http://docs.oracle.com/javaee/6/tutorial/doc/bnaby.html , and the technical β€œ.war” is the same as ZIP compressed folder renamed to ".zip".)

(Also note that I will really take the time to contact maven, since after that you know about a serious building tool and can create jar , ear , war , etc. in the standard process).

+2
source

If this is a Maven project, then open a console, go to where the pom.xml file is located:

 mvn package 

It will create the file {artifactId} - {version} .war in the $ {basedir} / target directory . This assumes 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 is specified, the default will be jar .

More details here and here .

+1
source

Source: https://habr.com/ru/post/984215/


All Articles