如何在使用 spring 构建 web 项目时修复 MojoFailureException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7927997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix MojoFailureException while using spring too to build web project
提问by charles
Recently I use spring STS with roo 1.2.0.M1 to build a web project. I set up the jpa and create a entity with some field and create a repository and a service layer for the entity, and then when I perform tests, it gives me the following error:
最近在用spring STS和roo 1.2.0.M1搭建一个web项目。我设置了 jpa 并创建了一个带有某个字段的实体,并为该实体创建了一个存储库和一个服务层,然后当我执行测试时,它给了我以下错误:
roo> perform tests
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building WebApplication 0.1.0.BUILD-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- aspectj-maven-plugin:1.2:compile (default) @ WebApplication ---
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ WebApplication ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ WebApplication ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- aspectj-maven-plugin:1.2:test-compile (default) @ WebApplication ---
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ WebApplication ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ WebApplication ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.8:test (default-test) @ WebApplication ---
[INFO] Surefire report directory: /Users/charlesli/Documents/workspace-spring/WebApplication/target/surefire-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.936s
[INFO] Finished at: Fri Oct 28 20:59:59 EST 2011
[INFO] Final Memory: 6M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.8:test (default-test) on project WebApplication: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/charlesli/Documents/workspace-spring/WebApplication/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
And I run the mvn test in the terminal, and I get the following errors:
我在终端中运行 mvn 测试,出现以下错误:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.614s
[INFO] Finished at: Fri Oct 28 21:06:50 EST 2011
[INFO] Final Memory: 6M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.8:test (default-test) on project WebApplication: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/charlesli/Documents/workspace-spring/WebApplication/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.8:test (default-test) on project WebApplication: There are test failures.
Please refer to /Users/charlesli/Documents/workspace-spring/WebApplication/target/surefire-reports for the individual test results.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.
Please refer to /Users/charlesli/Documents/workspace-spring/WebApplication/target/surefire-reports for the individual test results.
at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution(SurefireHelper.java:74)
at org.apache.maven.plugin.surefire.SurefirePlugin.writeSummary(SurefirePlugin.java:644)
at org.apache.maven.plugin.surefire.SurefirePlugin.executeAfterPreconditionsChecked(SurefirePlugin.java:640)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:103)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
I use the following commands to build the project:
我使用以下命令来构建项目:
jpa setup --database MYSQL --provider HIBERNATE --databaseName App --hostName localhost --password root --persistenceUnit app --transactionManager appTransactionManager --userName root
entity --class ~.app.domain.DomainObjBaseModel --mappedSuperclass --persistenceUnit app --transactionManager appTransactionManager
// After running the above command, I manually add the following stuff in DomainObjBaseModel, because I don't know how to customise the roo auto generate stuff
@Id @GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Column(unique = true, name = "id", nullable = false, length=32)
private String id;
// After this action, I continue run the following commands.
entity --class ~.app.domain.Application --extends com.crazysoft.web.app.domain.DomainObjBaseModel --persistenceUnit app --transactionManager appTransactionManager --serializable --testAutomatically
repository jpa --interface ~.app.repository.ApplicationRepository --entity ~.app.domain.Application
service --interface ~.app.service.ApplicationService --entity ~.app.domain.Application
This is the configuration of the maven plugin:
这是maven插件的配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
After I finish the above job, and run perform teststhrough STS roo shell, and I get the above error.
完成上述工作后,并perform tests通过 STS roo shell运行,出现上述错误。
Is there anyone know that why this exception occurs? Do I do something wrong? And how to fix it?
有没有人知道为什么会发生这个异常?我做错了什么吗?以及如何修复它?
Please help me!
请帮我!
Thank you in advance!
先感谢您!
回答by Ralph
One or more tests are not working.
一项或多项测试无效。
Have a look at the files located at: /Users/charlesli/Documents/workspace-spring/WebApplication/target/surefire-reports(usually the bigger files contain a problem)
查看位于以下位置的文件:( /Users/charlesli/Documents/workspace-spring/WebApplication/target/surefire-reports通常较大的文件包含问题)
There you will find the test results, and the test that is broken. The Stacktrace containing in this file will guide you to the problem.
在那里你会找到测试结果,以及被破坏的测试。此文件中包含的 Stacktrace 将引导您解决问题。
(BTW: you can run the tests in eclipse via JUnit plugin (Package explorer, right click, run as JUnit) too, then you will see the stack trace in the IDE and do not need to search in the files.)
(顺便说一句:您也可以通过 JUnit 插件(Package explorer,右键单击,作为 JUnit 运行)在 eclipse 中运行测试,然后您将在 IDE 中看到堆栈跟踪,而无需在文件中搜索。)
I guess, that the DB connection is not correct. But this is only a guess.
我猜,数据库连接不正确。但这只是一个猜测。
回答by Pankaj Kumar
Right click on Project-> Properties--> select project facets--> choose Java correct version which is installed on your system. Then it will works fine.
右键单击项目-> 属性--> 选择项目方面--> 选择系统上安装的 Java 正确版本。然后它会正常工作。
回答by Gadhia Reema
You can replace the environment from jre to jdk as follows if it also shows compiler unavailable :
如果还显示编译器不可用,您可以将环境从 jre 替换为 jdk,如下所示:
- project_name > Build Path > Configure Build Path > Libraries > (double-click) JRE System Libraries > Alternate Jre : jdk 1.8 >ok
- Then from Installed JRES option in Libraries select jdk 1.8
- Project > Clean
- Maven > Update
- 项目名称 > 构建路径 > 配置构建路径 > 库 >(双击)JRE 系统库 > 备用 Jre:jdk 1.8 >ok
- 然后从库中的已安装 JRES 选项中选择 jdk 1.8
- 项目 > 清洁
- Maven > 更新

![无法为 XML 架构命名空间找到 Spring NamespaceHandler [http://www.springframework.org/schema/security]](/res/img/loading.gif)