我和maven有一个奇怪的问题。我不确定它是什么但似乎在编译我的项目时(使用mvn clean编译)似乎包含了一个错误版本的依赖项。
我想要包含的库是 commons-io 2.4版。当我检查我的IDE时,看起来加载了正确的版本。在我的IDE中编译工作正常。
然而,当我用maven编译项目时,这行代码失败了:
FileUtils.write(new File(propertyService.getStatusPageLocation()), "Some string value");
由于错误:
[ERROR] /C:/projects/my-project/client-externalclient/src/main/java/be/roots/myproject/client/externalclient/jobs/WriteStatusPageJob.java:[60,22] cannot find symbol
[ERROR] symbol: method write(java.io.File,java.lang.String)
据我所知,该类确实具有该签名的方法。 问题似乎只发生在我的电脑上。
dependency:tree命令显示以下信息:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ shared-internal ---
[INFO] be.roots.myproject:shared-internal:bundle:3.40-SNAPSHOT
[INFO] +- be.roots.myproject:shared-external:jar:3.40-SNAPSHOT:compile
[INFO] | +- org.slf4j:slf4j-log4j12:jar:1.7.7:runtime
[INFO] | \- log4j:log4j:jar:1.2.17:runtime
[INFO] +- org.apache.cxf:cxf-rt-frontend-jaxrs:jar:3.0.4.redhat-621107:compile
[INFO] | +- org.apache.cxf:cxf-core:jar:3.0.4.redhat-621107:compile
[INFO] | | +- org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:compile
[INFO] | | \- org.apache.ws.xmlschema:xmlschema-core:jar:2.2.1:compile
[INFO] | +- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile
[INFO] | +- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] | \- org.apache.cxf:cxf-rt-transports-http:jar:3.0.4.redhat-621107:compile
[INFO] +- joda-time:joda-time:jar:2.5:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] | \- org.objenesis:objenesis:jar:2.1:test
[INFO] +- org.powermock:powermock-api-mockito:jar:1.6.2:test
[INFO] | +- org.mockito:mockito-all:jar:1.10.19:test
[INFO] | \- org.powermock:powermock-api-support:jar:1.6.2:test
[INFO] | +- org.powermock:powermock-core:jar:1.6.2:test
[INFO] | | \- org.javassist:javassist:jar:3.19.0-GA:test
[INFO] | \- org.powermock:powermock-reflect:jar:1.6.2:test
[INFO] +- org.powermock:powermock-module-junit4:jar:1.6.2:test
[INFO] | \- org.powermock:powermock-module-junit4-common:jar:1.6.2:test
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- org.apache.camel:camel-sql:jar:2.15.1.redhat-621107:compile
[INFO] | +- org.apache.camel:camel-core:jar:2.15.1.redhat-621107:compile
[INFO] | +- org.springframework:spring-jdbc:jar:3.2.12.RELEASE:compile
[INFO] | | \- org.springframework:spring-tx:jar:3.2.12.RELEASE:compile
[INFO] | +- com.sun.xml.bind:jaxb-core:jar:2.2.11:compile
[INFO] | \- com.sun.xml.bind:jaxb-impl:jar:2.2.11:compile
[INFO] +- commons-codec:commons-codec:jar:1.10:compile
[INFO] +- commons-io:commons-io:jar:2.4:compile
[INFO] +- commons-collections:commons-collections:jar:3.2.1.redhat-7:test
[INFO] +- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO] +- com.jcraft:jsch:jar:0.1.51:compile
[INFO] +- org.springframework:spring-core:jar:3.2.12.RELEASE:compile
[INFO] | \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] +- org.springframework:spring-context-support:jar:3.2.12.RELEASE:compile
[INFO] | +- org.springframework:spring-beans:jar:3.2.12.RELEASE:compile
[INFO] | \- org.springframework:spring-context:jar:3.2.12.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:3.2.12.RELEASE:compile
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | \- org.springframework:spring-expression:jar:4.1.6.RELEASE:compile
[INFO] +- commons-net:commons-net:jar:3.3:compile
[INFO] +- com.google.guava:guava:jar:18.0:compile
[INFO] +- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.6.3:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.6.3:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.3:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.3:compile
[INFO] | +- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.6.3:compile
[INFO] | \- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
[INFO] +- javax:javaee-web-api:jar:6.0:provided
[INFO] \- be.roots:zxing-osgi:jar:1.0:compile
[INFO] +- com.google.zxing:javase:jar:2.3.0:compile
[INFO] \- com.google.zxing:core:jar:2.3.0:compile
还显示正在加载的库。
dependency:build-classpath命令给出了这个列表:
C:\Users\MyName\.m2\repository\be\roots\myproject\shared-external\3.40-SNAPSHOT\shared-external-3.40-SNAPSHOT.jar;C:\Users\MyName\.m2\repository\org\slf4j\slf4j-log4j12\1.7.7\slf4j-log4j12-1.7.7.jar;C:\Users\MyName\.m2\repository\log4j\log4j\1.2.17\log4j-1.2.17.jar;C:\Users\MyName\.m2\repository\org\apache\cxf\cxf-rt-frontend-jaxrs\3.0.4.redhat-621107\cxf-rt-frontend-jaxrs-3.0.4.redhat-621107.jar;C:\Users\MyName\.m2\repository\org\apache\cxf\cxf-core\3.0.4.redhat-621107\cxf-core-3.0.4.redhat-621107.jar;C:\Users\MyName\.m2\repository\org\codehaus\woodstox\woodstox-core-asl\4.4.1\woodstox-core-asl-4.4.1.jar;C:\Users\MyName\.m2\repository\org\apache\ws\xmlschema\xmlschema-core\2.2.1\xmlschema-core-2.2.1.jar;C:\Users\MyName\.m2\repository\javax\ws\rs\javax.ws.rs-api\2.0.1\javax.ws.rs-api-2.0.1.jar;C:\Users\MyName\.m2\repository\javax\annotation\javax.annotation-api\1.2\javax.annotation-api-1.2.jar;C:\Users\MyName\.m2\repository\org\apache\cxf\cxf-rt-transports-http\3.0.4.redhat-621107\cxf-rt-transports-http-3.0.4.redhat-621107.jar;C:\Users\MyName\.m2\repository\joda-time\joda-time\2.5\joda-time-2.5.jar;C:\Users\MyName\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\MyName\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\MyName\.m2\repository\org\mockito\mockito-core\1.10.19\mockito-core-1.10.19.jar;C:\Users\MyName\.m2\repository\org\objenesis\objenesis\2.1\objenesis-2.1.jar;C:\Users\MyName\.m2\repository\org\powermock\powermock-api-mockito\1.6.2\powermock-api-mockito-1.6.2.jar;C:\Users\MyName\.m2\repository\org\mockito\mockito-all\1.10.19\mockito-all-1.10.19.jar;C:\Users\MyName\.m2\repository\org\powermock\powermock-api-support\1.6.2\powermock-api-support-1.6.2.jar;C:\Users\MyName\.m2\repository\org\powermock\powermock-core\1.6.2\powermock-core-1.6.2.jar;C:\Users\MyName\.m2\repository\org\javassist\javassist\3.19.0-GA\javassist-3.19.0-GA.jar;C:\Users\MyName\.m2\repository\org\powermock\powermock-reflect\1.6.2\powermock-reflect-1.6.2.jar;C:\Users\MyName\.m2\repository\org\powermock\powermock-module-junit4\1.6.2\powermock-module-junit4-1.6.2.jar;C:\Users\MyName\.m2\repository\org\powermock\powermock-module-junit4-common\1.6.2\powermock-module-junit4-common-1.6.2.jar;C:\Users\MyName\.m2\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;C:\Users\MyName\.m2\repository\org\apache\camel\camel-sql\2.15.1.redhat-621107\camel-sql-2.15.1.redhat-621107.jar;C:\Users\MyName\.m2\repository\org\apache\camel\camel-core\2.15.1.redhat-621107\camel-core-2.15.1.redhat-621107.jar;C:\Users\MyName\.m2\repository\org\springframework\spring-jdbc\3.2.12.RELEASE\spring-jdbc-3.2.12.RELEASE.jar;C:\Users\MyName\.m2\repository\org\springframework\spring-tx\3.2.12.RELEASE\spring-tx-3.2.12.RELEASE.jar;C:\Users\MyName\.m2\repository\com\sun\xml\bind\jaxb-core\2.2.11\jaxb-core-2.2.11.jar;C:\Users\MyName\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.11\jaxb-impl-2.2.11.jar;C:\Users\MyName\.m2\repository\commons-codec\commons-codec\1.10\commons-codec-1.10.jar;C:\Users\MyName\.m2\repository\commons-io\commons-io\2.4\commons-io-2.4.jar;C:\Users\MyName\.m2\repository\commons-collections\commons-collections\3.2.1.redhat-7\commons-collections-3.2.1.redhat-7.jar;C:\Users\MyName\.m2\repository\org\slf4j\slf4j-api\1.7.7\slf4j-api-1.7.7.jar;C:\Users\MyName\.m2\repository\com\jcraft\jsch\0.1.51\jsch-0.1.51.jar;C:\Users\MyName\.m2\repository\org\springframework\spring-core\3.2.12.RELEASE\spring-core-3.2.12.RELEASE.jar;C:\Users\MyName\.m2\repository\commons-logging\commons-logging\1.1.3\commons-logging-1.1.3.jar;C:\Users\MyName\.m2\repository\org\springframework\spring-context-support\3.2.12.RELEASE\spring-context-support-3.2.12.RELEASE.jar;C:\Users\MyName\.m2\repository\org\springframework\spring-beans\3.2.12.RELEASE\spring-beans-3.2.12.RELEASE.jar;C:\Users\MyName\.m2\repository\org\springframework\spring-context\3.2.12.RELEASE\spring-context-3.2.12.RELEASE.jar;C:\Users\MyName\.m2\repository\org\springframework\spring-aop\3.2.12.RELEASE\spring-aop-3.2.12.RELEASE.jar;C:\Users\MyName\.m2\repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;C:\Users\MyName\.m2\repository\org\springframework\spring-expression\4.1.6.RELEASE\spring-expression-4.1.6.RELEASE.jar;C:\Users\MyName\.m2\repository\commons-net\commons-net\3.3\commons-net-3.3.jar;C:\Users\MyName\.m2\repository\com\google\guava\guava\18.0\guava-18.0.jar;C:\Users\MyName\.m2\repository\com\fasterxml\jackson\dataformat\jackson-dataformat-xml\2.6.3\jackson-dataformat-xml-2.6.3.jar;C:\Users\MyName\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.6.3\jackson-core-2.6.3.jar;C:\Users\MyName\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.6.3\jackson-annotations-2.6.3.jar;C:\Users\MyName\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.6.3\jackson-databind-2.6.3.jar;C:\Users\MyName\.m2\repository\com\fasterxml\jackson\module\jackson-module-jaxb-annotations\2.6.3\jackson-module-jaxb-annotations-2.6.3.jar;C:\Users\MyName\.m2\repository\org\codehaus\woodstox\stax2-api\3.1.4\stax2-api-3.1.4.jar;C:\Users\MyName\.m2\repository\javax\javaee-web-api\6.0\javaee-web-api-6.0.jar;C:\Users\MyName\.m2\repository\be\roots\zxing-osgi\1.0\zxing-osgi-1.0.jar;C:\Users\MyName\.m2\repository\com\google\zxing\javase\2.3.0\javase-2.3.0.jar;C:\Users\MyName\.m2\repository\com\google\zxing\core\2.3.0\core-2.3.0.jar
有谁知道我还可以尝试调试此问题?
答案 0 :(得分:1)
IDE与mvn
命令之间可能存在差异的是使用的Java版本。请检查你的路径
答案 1 :(得分:0)
检查您的ide中的maven设置。 可以在IDE中选择不同的maven路径和自定义settings.xml。
答案 2 :(得分:0)
我发现了什么是错的,结果却是一个相当奇特的问题。
对于另一个项目,我安装了高级图像API(http://www.oracle.com/technetwork/java/javase/tech/jai-142803.html),其中包括将额外的.jar文件添加到java sdk中,这些文件将包含在您的核心Java安装中。
在所有libary的.jar文件中,还有较旧版本的commons-io,默认包含在内。
一旦我删除了该库,一切都进展顺利。