0

I am trying to run my java web app on AWS EC2 instance. The error I am getting is

no main manifest attribute, in app.jar

Going through other questions, I found that the problem can be with MANIFEST.mf file. I have that file under META-INF folder, however its missing Main Class tag.

I developed Java web app using servlets and stuff, but I didn't use SpringBoot, and I am unsure what the starting point of my program is.

Here is a part of my pom.xml:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.3.1</version>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.2.0</version>
    </plugin>

I thought that maven-jar-plugin would solve this by itself, but unfortunately that is not the case.

As a side note, I tried both war and jar packaging. Any ideas how to make this work? Should I hardcode something in MANIFEST.mf by myself?

My goal is to start my webapp on EC2 using this command:

java -jar app.jar

1 Answers1

0

for the maven-jar-plugin there is a place to configure the manifest. I have it like this in my project

my project is years old so please have a look at the documentation for the plugin: https://maven.apache.org/plugins/maven-jar-plugin/examples/manifest-customization.html

<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <version>2.3.2</version>
      <configuration>
             <archive>
                 <manifest>
                     <addClasspath>true</addClasspath>
                     <mainClass>webServer.main</mainClass>
                 </manifest>
             </archive>
      </configuration>
</plugin>  
bgore
  • 98
  • 1
  • 11
  • I am not sure how to configure manifest in my case because its a web app and doesn't have main. – babotrojka Dec 08 '21 at 21:40
  • every java program requires a main method. in this case its in a class also called main. Your project if it runs will have a main method. you need to point the tag to the class where your main method can be found – bgore Dec 09 '21 at 15:10
  • As this answer says -> https://stackoverflow.com/questions/8630496/main-class-of-a-tomcat-web-application, web application does not have a main class. Tomcat creates it, but thats outside of my reach – babotrojka Dec 09 '21 at 16:51
  • If you cant locate a main file inside of tomcat to point to you most likely cant use maven jar plugin and will have to look into the tomcat documentation – bgore Dec 10 '21 at 11:37