我正在尝试在运行时搜索项目中的类路径。我们使用 Maven 进行构建管理,使用 Hudson 进行 CI。当然,在我本地的盒子上,一切都很好。但是,当 Hudson 运行单元测试时,它无法找到构建期间生成的类 - Maven 应该将它们放入 ./target/classes
中,但是当我记录类路径时 (来自 Hudson 的 System.getProperty("java.class.path")
) 它只给了我一个包含两个与 maven 相关的 JAR 的列表——根本没有目录,当然也不是当前项目的编译器输出目录。这是哈德森的错吗?马文的?我是否以错误的方式处理这个问题?
ETA:我认为这可能已通过升级 Hudson 使用的 Maven 运行时来解决。问题是我们正在通过反射寻找插件类,类似于 这篇文章——不是实际的代码,但它给了你想法。不管怎样,听起来 Hudson 使用的类路径只是“引导”实际的测试工具;不管出于什么原因,它现在似乎已经修复了。长话短说:如果您有类似的问题,请尝试升级您的 Maven。
I'm trying to search the classpath in my project at runtime. We use Maven for build management and Hudson for CI. On my local box, of course, everything works great. However, when Hudson is running unit tests, it can't find classes generated during the build -- Maven should be putting them in ./target/classes
, but when I log the classpath (System.getProperty("java.class.path")
) from Hudson it only gives me a list with two maven-related JARs -- no directories at all, and certainly not the current project's compiler output directory. Is this Hudson's fault? Maven's? Am I going about this the wrong way?
ETA: I think this might have been fixed by upgrading the Maven runtime used by Hudson. The problem was that we were looking for plugin classes via reflection, similar to the ideas in this post -- not that actual code, but it gives you the idea. Anyway, it sounds like Hudson was using a classpath that only "bootstrapped" the actual test harness; for whatever reason it seems to be fixed now. Long story short: if you have a similar problem, try upgrading your Maven.
发布评论
评论(1)
两个修复。一、升级Maven。第二,不要依赖类路径黑客来迭代类加载器可以看到的东西,就像描述中链接的“资源发现”技巧一样。
Two fixes. One, upgrade Maven. Two, don't rely on classpath hackery to iterate over things your classloader can see, a la the "resource discovery" trick linked to in the description.