0

There is a java webapp with an embedded tomcat 7 that is built with this instructions (Using tomcat7-maven-plugin).

this webapp is launching with a jar file like this: java -jar webapp.jar

Question: How to run a main class after launching this embedded tomcat?

Saif Asif
  • 5,516
  • 3
  • 31
  • 48
Amin Sh
  • 2,684
  • 2
  • 27
  • 42

2 Answers2

1

What you need is to setup your application's entry point. For this you need to configure your main class inside the jar's Manifest file.

Something like

Manifest-Version: 1.0.1
Created-By: <jdk_version>
Main-Class: fully.qalified.class.name.with.main.method

For more details on Manifest, take a look into this link here

For making this step part of your maven build cycle, you need to make some changes in the mave.jar.plugin. Something like

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
  <archive>
    <manifest>
    <mainClass>fully.qalified.class.name.with.main.method</mainClass>
    </manifest>
  </archive>
</configuration>
</plugin>

The final jar that is created will have your main method as the applications entry point

Saif Asif
  • 5,516
  • 3
  • 31
  • 48
  • but there are these lines in manifest file already: `Manifest-Version: 1.0 Main-Class: org.apache.tomcat.maven.runner.Tomcat7RunnerCli` – Amin Sh May 14 '14 at 07:44
  • then why not append a call to your main method inside the `Tomcat7RunnerCli ` ? – Saif Asif May 14 '14 at 07:48
  • your'e right, I think I should override that. Isn't there another way to have secondary `Main-Class` in manifest? – Amin Sh May 14 '14 at 08:09
  • AFAIK, it only seems logical to have a single main method serving as the entry point of the application. Other than that, you can have as many main methods you like ! – Saif Asif May 14 '14 at 10:18
0

If I understood your question correctly. In Eclipse, Right click the project and pick "Run on Server."

Steve Waters
  • 3,348
  • 9
  • 54
  • 94