我想使用Maven创建一个App Engine项目,如下所述:https://developers.google.com/appengine/docs/java/tools/maven 但遇到一些问题。
mvn -v
输出
Maven home: D:\Shared\apache-maven-3.0.5\bin\..
Java version: 1.7.0_13, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_13\jre
Default locale: de_AT, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
和
mvn archetype:generate
也按预期工作,但是当我输入
时com.google.appengine.archetypes:guestbook-archetype
之后没有任何事情发生,这意味着它再次提示“选择一个数字或应用过滤器[..] ”。
然而,我可以使用问题Maven GAE archetype not working中的修改命令创建项目:
mvn archetype:generate -DarchetypeGroupId=com.google.appengine.archetypes -DarchetypeArtifactId=guestbook-archetype -DarchetypeVersion=1.7.7
输出结果为:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom >>
>
[INFO]
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom <<
<
[INFO]
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom --
-
[INFO] Generating project in Interactive mode
[INFO] Archetype repository missing. Using the one from [com.google.appengine.ar
chetypes:guestbook-archetype:1.7.7] found in catalog remote
然后它允许我为4个属性定义4个值,然后打印几个同样表示[INFO] BUILD SUCCESS
的行。
但是,当我切换到目录(在此示例中使用cd a
)并运行mvn verify
或mvn appengine:devserver
时,以下测试失败:
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.526 sec
Results :
Failed tests: testDoGet(a.GuestbookServletTest): expected:<Hello, test[]
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.826s
[INFO] Finished at: Sun May 05 21:47:32 CEST 2013
[INFO] Final Memory: 14M/212M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
10:test (default-test) on project a: There are test failures.
[ERROR]
[ERROR] Please refer to D:\Shared\maven-projects\a\target\surefire-reports for t
he individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[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 rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureExc
eption
在文件D:\Shared\maven-projects\a\target\surefire-reports\a.GuestbookServletTest.txt
中,我注意到以下内容:
junit.framework.ComparisonFailure: expected:<Hello, test[]
> but was:<Hello, test[
]
>
作为Hex,它是
6a 75 6e 69 74 2e 66 72 61 6d 65 77 6f 72 6b 2e 43 6f 6d 70 61 72 69 73 6f 6e 46 61 69 6c 75 72 65 3a 20 65 78 70 65 63 74 65 64 3a 3c 48 65 6c 6c 6f 2c 20 74 65 73 74 5b 5d 0a 3e 20 62 75 74 20 77 61 73 3a 3c 48 65 6c 6c 6f 2c 20 74 65 73 74 5b 0d 5d 0a 3e
如您所见,在实际输出中,方括号之间有一个0d
字符。在期望中,方括号之间没有任何东西。我查了一下它似乎是回车。
我该怎么办?
这可能是我的Cp1252
而非UTF-8
平台的问题吗?
我还尝试生成项目设置file.encoding
,如
mvn archetype:generate -DarchetypeGroupId=com.google.appengine.archetypes -DarchetypeArtifactId=guestbook-archetype -DarchetypeVersion=1.7.7 -Dfile.encoding="UTF-8"
甚至
mvn archetype:generate -DarchetypeGroupId=com.google.appengine.archetypes -DarchetypeArtifactId=guestbook-archetype -DarchetypeVersion=1.7.7 -Dfile.encoding="Cp1252"
但输出中仍然存在exta 0d
字符。
如果有人能帮助我开展这项工作,我将不胜感激。
答案 0 :(得分:4)
事实证明,JUnit测试中存在一个错误。
73
中的行GuestbookServletTest.java
必须更改为:
assertEquals("Hello, " + currentUser.getNickname() + "\n", stringWriter.toString());
到
assertEquals("Hello, " + currentUser.getNickname() + System.getProperty("line.separator"), stringWriter.toString());
因为Windows使用\r\n
作为路径分隔符。我在https://code.google.com/p/googleappengine/issues/detail?id=9272提交了一份错误报告,以防有人感兴趣。
答案 1 :(得分:0)
您可以尝试在pom.xml中添加以下行吗
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.resourceEncoding>UTF-8</project.build.resourceEncoding>
<maven.compile.encoding>UTF-8</maven.compile.encoding>
</properties>
您可以按照this主题进行类似的讨论