Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate .war file from web app containing just HTML, CSS & JavaScript

I am trying to create a war file that will be deployed on a web/application server.

The source files of the app are purely HTML, CSS, and JavaScript. There is a separate war file for our REST API and for the rest of our backend code.

Most of the guides out there talk about using java to compile, and pointing to WEB-INF folders etc.

However, as I mentioned, in the HTML/CSS/JS war, I don't use any Java, don't use WEB-INF, and there are no servlets or other things you would normally see in a "Java" war file.

How do I compile or create this type of war file?

The contents look like this:

WebContent/HTML WebContent/CSS WebContent/JS

All libraries for JavaScript contained within JS folder.

Would this work: Simply run:

src.dist="./WebContent"
app.name="example"
app.version=1
work.home="./temp"

jar jarfile="${src.dist}/${app.name}-${app.version}.war"
     basedir="${work.home}"

Obviously I would have set up the rest of the script correctly.

like image 388
sam9046 Avatar asked Nov 19 '13 19:11

sam9046


People also ask

How do I create a WAR file for Web application?

To create war file, you need to use jar tool of JDK. You need to use -c switch of jar, to create the war file. Go inside the project directory of your project (outside the WEB-INF), then write the following command: jar -cvf projectname.

Can you make an app with HTML and CSS?

Yes, you read it right in the title of this article. In this article, we are going to build an Android App with HTML, CSS, and JavaScript in Android Studio.

What is a WAR file and how do you create a WAR file?

A WAR file is an archive file, used to group all application files into a convenient package. A WAR file can be created with the jar command, included in the Java runtime environment, or a ZIP utility program such as WinZip .

What is a .WAR file?

In software engineering, a WAR file (Web Application Resource or Web application ARchive) is a file used to distribute a collection of JAR-files, JavaServer Pages, Java Servlets, Java classes, XML files, tag libraries, static web pages (HTML and related files) and other resources that together constitute a web ...


1 Answers

This is extremely simple:

  1. Create a folder
  2. Add a src/main/webapp folder
  3. Add all of your HTML, CSS and JS files to the src/main/webapp folder
  4. Add an empty web.xml file to the src/main/webapp/WEB-INF directory.
  5. add a maven pom.xml
  6. add the maven-war-plugin to your pom.xml, with the following configuration:

    <!--  create the war -->
    <plugin>
      <artifactId>maven-war-plugin</artifactId>
      <configuration>
        <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
      </configuration>
    </plugin>
    
  7. run mvn clean install!

like image 199
Marco Avatar answered Sep 19 '22 20:09

Marco