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.
This is extremely simple:
- Create a folder
- Add a
src/main/webapp
folder
- Add all of your HTML, CSS and JS files to the
src/main/webapp
folder
- Add an empty web.xml file to the
src/main/webapp/WEB-INF
directory.
- add a maven pom.xml
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>
run mvn clean install!
If you are creating a war file, then you are deploying on a Java based web application server, something like Tomcat or Wildfly.
If you are using eclipse, you can do so by New > Dynamic Web Project
(maybe name it foo-bar), click next, next and finish. Then open that foo-bar project and create your css and js folders under WebContent like so.
\WebContent\css
\WebContent\js
\WebContent\index.html
\WebContent\foo-bar.html
You can right click the foo-bar project > Export > Web WAR file
.
When you deploy it on say Tomcat, you can test to access your static content like so
http://localhost:8080/foo-bar/css/foo-bar.css
http://localhost:8080/foo-bar/js/foo-bar.js
http://localhost:8080/foo-bar/foo-bar.html
Hope this helps.