1

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 から取得し、次のコマンドで実行すると、正常に機能しました。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 に答える