0

I have a jar with two main class. I'm trying to run the main class using the command

java -cp TestNGExamples-0.0.1-SNAPSHOT.jar:lib/* com.test.integration.TestMain

but I get the following error

Error: Could not find or load main class com.test.integration.TestMain

I don't want to edit the manifest file since I already have a Main class given there. lib folder is there in the jar and I've checked it.

Can anyone tell me what I'm doing wrong here?

Edit:

This was my referral : Run a JAR file from the command line and specify classpath

azhar
  • 11
  • 1
  • 4

1 Answers1

0
If I am not wrong you are using maven. If so you can specify your main class in pom.xml.
You can do something like this.

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>Main_Class_Package_Name</mainClass>
            </manifest>
          </archive>
        </configuration
      </plugin>
    </plugins>
  </build>
Sidhajyoti
  • 59
  • 4
  • Thanks for your anser Sidhajyothi. Your answer was helpful for me to solve the problem because I realised that it was the packaging issue, so I used the maven shade plugin to package and it worked. But this was not exactly the answer. – azhar Jun 22 '20 at 07:44
  • Cool..Good to hear that some how my solutions helped for you. – Sidhajyoti Jun 22 '20 at 07:46