pawel
pawel

Reputation: 6146

I cant run my Maven Project - no main class found

I've never used Maven or Selenium, so I have quite simple question: I've followed this tutorial: http://docs.seleniumhq.org/docs/03_webdriver.jsp

So, after mvn clean install and importing my project to NetBeans (via projet/open project menu). I created new main class via Wizard (New => Java Main Class) and Built my project.

Build had succeed but when I want to run my project it shows "No Main class found".

WHY?

My project folder is /user/webtest2/ and my main class file (Selenium2Example.java) is in the root folder of this project (as pom.xml).

Upvotes: 0

Views: 5610

Answers (2)

Geet Kaur
Geet Kaur

Reputation: 11

This was so silly. I was getting the exception despite having correct entry point configured in pom.xml.

In my case this error was occurring because I forgot to mention "string[args]" in main method arguments,

ie I had written - public static void main() --- INCORRECT Instead Of public static void main (String args[]) -- CORRECT

Upvotes: 1

Pavel Janicek
Pavel Janicek

Reputation: 14748

Ok, I have looked at the pom.xml in my maven webdriver project and I think you should chcek this:

 <!-- Create JAR manifest with main class, but without Maven descriptor, so clients don't see this file -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <addMavenDescriptor>false</addMavenDescriptor>
                    <manifest>
                        <mainClass>com.deutscheboerse.test.MyTest</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

While in the projet folder I have under package com.deutscheboerse.test created file (java Class) which is named MyTest and this class contains main method. Snippet from the code:

public static void main(String[] args) throws Exception {
    myTest(args[0], args[1], args[2], price);

}

While the method mytest() does the magic:

public static void myTest(String driver, String login, String password, Price price) throws Exception {
    PerfTests tests = new PerfTests(USED_ENVIRONMENT, driver);

    tests.login(login, password);
    //... and other steps
}

Long story short Check that your pom.xml contains path to the main class and this class actually contains main method

Upvotes: 0

Related Questions