1

I have a Maven Web Application that contains only a single class in the Source Packages folder. I have obtained the war file from this project which I would like to copy and run on another machine. I would like to be able to run only that specific class using the commandline.

The reason why I still want to use the war file is because that class implements a RESTful service so I don't know if there is another way to go (like making it a jar and end right there). My war file also contains several dependencies and one of them has the provided scope:

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>

This is an extract from the pom.xml file and is the only dependency that does not appear in the WEB-INF/lib folder. However, I don't know if this is the problem.

My class is named ClientSide and is under the client package. Running the command:

    java -cp warFileName.war client.ClientSide

resulted in this error:

Error: Could not find or load main class client.ClientSide

Adding Main-Class: client.ClientSide to the manifest file did not change anything. I have tried the solutions proposed here: How do I run a class in a WAR from the command line? but with no luck. This error would keep repeating.

The only way I can run that class is by right-clicking on the class inside the Web Application and select Run File from netbeans, which is very annoying.

Cœur
  • 37,241
  • 25
  • 195
  • 267
MihaiD
  • 63
  • 1
  • 10

1 Answers1

0

You can use

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <configuration>
            <archive>
                <manifest>
                    <addClasspath>true</addClasspath>
                    <mainClass>client.ClientSide.YourMain</mainClass>
                    <classpathPrefix>./lib/</classpathPrefix>
                </manifest>
            </archive>
        </configuration>
    </plugin>

You can put this in your main pom.xml, Here you are telling where is your main class

Ruchira Gayan Ranaweera
  • 34,993
  • 17
  • 75
  • 115
  • After adding that plugin I got the following error: `no main manifest attribute, in ClientSideCommunication-1.0-SNAPSHOT.war` when I ran the `java -jar ClientSideCommunication-1.0-SNAPSHOT.war` command. – MihaiD Aug 19 '14 at 09:26