mvn test-compile
)时,它无法找到测试类中使用的测试类。例如,无法编译类UserTest
,因为编译器找不到在User
类中使用的类UserTest
。问题很可能是在test-compile
阶段不包括目标文件夹的类路径中,这很奇怪,因为我认为maven确实包含它。
如果有人有任何想法如何解决这个问题,我会很高兴。
pom.xml文件可以在http://github.com/tomasherman/JBTBackup/blob/master/pom.xml找到,就像项目的其他部分一样。
maven输出如下:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building JBTBackup Maven Webapp
[INFO] task-segment: [test-compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[WARNING] While downloading hibernate:hibernate:3.0.5
This artifact has been relocated to org.hibernate:hibernate:3.0.5.
[INFO] [compiler:compile {execution: default-compile}]
[INFO] No sources to compile
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/arg/workspace/JBTBackup/src/test/resources
[INFO] [sql:execute {execution: add-test-data}]
[INFO] Executing file: /tmp/pre-test-editdb.1278025605sql
[INFO] 0 of 0 SQL statements executed successfully
[INFO] [compiler:testCompile {execution: default-testCompile}]
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 2 source files to /home/arg/workspace/JBTBackup/target/test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/UserTest.java:[26,15] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.UserTest
[ERROR] /home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/UserTest.java:[27,15] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.UserTest
[ERROR] /home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/UserTest.java:[28,15] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.UserTest
[ERROR] /home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/BTFileTest.java:[23,15] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.BTFileTest
[ERROR] /home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/BTFileTest.java:[25,15] cannot find symbol
symbol : class BTFile
location: class org.tomasherman.JBTBackup.Resource.Entity.BTFileTest
[ERROR] /home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/UserTest.java:[26,29] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.UserTest
[ERROR] /home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/UserTest.java:[27,29] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.UserTest
[ERROR] /home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/UserTest.java:[28,29] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.UserTest
[ERROR] /home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/BTFileTest.java:[23,29] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.BTFileTest
[ERROR] /home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/BTFileTest.java:[25,31] cannot find symbol
symbol : class BTFile
location: class org.tomasherman.JBTBackup.Resource.Entity.BTFileTest
[INFO] 10 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
/home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/UserTest.java:[26,15] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.UserTest
/home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/UserTest.java:[27,15] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.UserTest
/home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/UserTest.java:[28,15] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.UserTest
/home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/BTFileTest.java:[23,15] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.BTFileTest
/home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/BTFileTest.java:[25,15] cannot find symbol
symbol : class BTFile
location: class org.tomasherman.JBTBackup.Resource.Entity.BTFileTest
/home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/UserTest.java:[26,29] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.UserTest
/home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/UserTest.java:[27,29] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.UserTest
/home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/UserTest.java:[28,29] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.UserTest
/home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/BTFileTest.java:[23,29] cannot find symbol
symbol : class User
location: class org.tomasherman.JBTBackup.Resource.Entity.BTFileTest
/home/arg/workspace/JBTBackup/src/test/java/org/tomasherman/JBTBackup/Resource/Entity/BTFileTest.java:[25,31] cannot find symbol
symbol : class BTFile
location: class org.tomasherman.JBTBackup.Resource.Entity.BTFileTest
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Thu Aug 26 12:54:37 CEST 2010
[INFO] Final Memory: 17M/172M
[INFO] ------------------------------------------------------------------------
感谢所有评论,Tomas Herman
答案 0 :(得分:4)
您必须将应用程序类移动到src / main / java / ...而不是src / main / resources,因为Maven假设(约定优于配置)您的java类位于src / main / java中。这意味着他们永远不会被编译。
答案 1 :(得分:2)
请注意,Maven已经无法编译要测试的类:
[INFO] [compiler:compile {execution: default-compile}]
[INFO] No sources to compile
@ Gopi的评论解释了为什么会这样。您应该将代码置于src/main/java
下以供Maven默认查看。
答案 2 :(得分:2)
UserTest.java
文件中的User
类没有明确的导入,这意味着应该在org.tomasherman.JBTBackup.Resource.Entity
包中的某个位置。
但是,src/test/java/org/tomasherman/JBTBackup/Resource/Entity
或src/main/java/org/tomasherman/JBTBackup/Resource/Entity
中都没有此类文件。
我无法在您的POM文件中看到任何可能生成此类的内容(如hbm2java)。也许你忘了犯了它?
答案 3 :(得分:1)
您是否尝试调用mvn compile test-compile,或者只是mvn clean install?