I have used maven plugin to build a war file for my project structure. And now when I run this war file, I get the error
Error: Could not find or load main class com.abc.HelloWorld.App
For some reason, when I check the war file, my main class is getting generated under WEB-INF/classes/com/abc/HelloWorld/
I have tried added a classpath to Manifest.MF
file, but it has not helped.
Here is my maven plugin for creating a war file. Also this project contains an embedded jetty server.
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webXml>WebContent\WEB-INF\web.xml</webXml>
<warName>${project.artifactId}-${project.version}</warName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.infor.HelloWorld.App</mainClass>
</manifest>
</archive>
<overlays>
<overlay>
<id>com.abc.HelloWorld</id>
<type>jar</type>
</overlay>
</overlays>
</configuration>
<executions>
<execution>
<id>default-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
I have tried this question, but it has not helped.
WebApp WAR files are a specialized jar files packaged for Web Containers to deploy from.
You can have a self-executing war file, but you'll wind up having a WAR file that has JAR behavior overlaid so that the
META-INF/MANIFEST.MF
and itsMain-Class
can instantiate Jetty, then load in the webapp itself into that Server instance.Take a look at the following project maintained by the Jetty Project.
https://github.com/jetty-project/embedded-jetty-live-war
It is important to be careful when:
META-INF/services/
filesServer
side of the self-executable to HTTP clients (don't let them download anything sensitive!) - this can be accomplished by putting the server parts of this startup in the/WEB-INF/
directoryAs stated on that project:
This project should provide a baseline for those investigating the use of Embedded Jetty from the point of view of a Self Executing WAR file.
The project has 4 main parts:
/thewebapp/
- this is the WAR file, the webapp, as it exists in its native format, with normal maven<packaging>war</packaging>
and a produced artifact that is just a WAR file that isn't (yet) self-executing./theserver/
- this is the Embedded Jetty Serverjetty.livewar.ServerMain.main(String args[])
which you customize to initialize your Jetty server and its WebApp. This project also is the place where you customize for things like JDBC servers libraries, JNDI, logging, etc. This project produces a uber-jar with all of the dependencies needed to run the server. Special care is taken with themaven-shade-plugin
to mergeMETA-INF/services/
files./server-bootstrap/
- this contains 2 small classes that sets up aLiveWarClassLoader
from the content in the live WAR and then runsjetty.livewar.ServerMain.main(String args[])
from this new ClassLoader. This project also contains the liveMETA-INF/MANIFEST.MF
that the live WAR will need/use/livewar-assembly/
- this is the project that ties together the above 3 projects into a Live/Executable WAR file. The artifacts from from the above 3 projects are unpacked by themaven-assembly-plugin
and put into place where they will be most functional (and safe). For example, the server classes from/theserver/
are placed in/WEB-INF/jetty-server/
to make them inaccessible from Web Clients accessing the WAR file.