1

Exception is coming while excuting maven program . I am using maven 2.2 Getting this exception while executing class using maven . This is my pom.xml

<modelVersion>4.0.0</modelVersion>
<groupId>com.infrasoft.ibs.retail</groupId>
<artifactId>ibs-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ibs-project</name>

<properties>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

    <dependencies>
    <dependency>
        <groupId>org.apache.shiro</groupId>
        <artifactId>shiro-core</artifactId>
        <version>1.2.1</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.6.4</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
                <encoding>${project.build.sourceEncoding}</encoding>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <classpathScope>test</classpathScope>
                <mainClass>ShiroDemo</mainClass>
            </configuration>
        </plugin>

    </plugins>
</build>

   StackTrace is 
  org.apache.maven.lifecycle.LifecycleExecutionException: An exception occured whi
 le executing the Java class. ShiroDemo
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
 ultLifecycleExecutor.java:719)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandalone
 Goal(DefaultLifecycleExecutor.java:569)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
 ltLifecycleExecutor.java:539)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
 dleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
  ts(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
 fecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:6
  0)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
   sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
      Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured
    while executing the Java class. ShiroDemo
    at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:345)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
      nManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
      ultLifecycleExecutor.java:694)
    ... 17 more
      Caused by: java.lang.ClassNotFoundException: ShiroDemo
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

Please help, what could be the reason? Thanks in advance

EDIT

ok, when I removed

   <configuration>
            <classpathScope>test</classpathScope>
            <mainClass>ShiroDemo</mainClass>
        </configuration>

from pom.xml and executed with followin command it worked properly. mvn compile exec:java -Dexec.mainClass="org.sample.test.ShiroDemo" -e

4

1 回答 1

0

您不需要指定 -Dexec.mainClass。你得到了正确的配置,只是不在 pom.xml 中。将其更改为以下内容:

<mainClass>org.sample.test.ShiroDemo</mainClass>
于 2013-01-30T19:29:38.713 回答