maven exec插件:org.apache.maven.plugin.MojoExecutionException和ClassNotFoundException

时间:2012-09-13 11:57:08

标签: maven-2

排除maven计划时出现例外情况。 我正在使用maven 2.2 使用maven执行类时获取此异常。 这是我的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)

请帮忙,可能是什么原因? 提前致谢

修改

好的,当我删除

   <configuration>
            <classpathScope>test</classpathScope>
            <mainClass>ShiroDemo</mainClass>
        </configuration>
从pom.xml

并使用followin命令执行它正常工作。 mvn compile exec:java -Dexec.mainClass =&#34; org.sample.test.ShiroDemo&#34; -e

1 个答案:

答案 0 :(得分:0)

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

<mainClass>org.sample.test.ShiroDemo</mainClass>