为什么此autorun-cmd注册表黑客会影响Java/Maven进程? [英] Why does this autorun-cmd registry hack affect a java/maven process?
问题描述
HKEY_CURRENT_USER \ Software \ Microsoft \ Command Processor \ Autorun的存在会导致Java测试失败. Github仓库进行测试: https://github.com/ajorpheus/final-frontier
The presence of an HKEY_CURRENT_USER\Software\Microsoft\Command Processor\Autorun causes a java test to fail. Github repo to test this out : https://github.com/ajorpheus/final-frontier
这是 此 发生后的后续问题.
This is a follow-up question after this happened.
摘要:显然是 注册表黑客 ,该命令允许每次打开cmd提示时都运行命令,从而对Java进程产生不利影响.
Summary : Apparently a registry hack which allows a command to be run every time the cmd prompt is opened, adversely affects the Java process.
首先,我想也许是"mvn干净测试"实际上解析为"mvn.bat干净测试"的事实.但是,我尝试提取mvn.bat文件中包含的java.exe命令并尝试直接使用它,但是遇到了同样的问题.
To begin with I thought, that perhaps it was the fact that 'mvn clean test' actually resolves to 'mvn.bat clean test'. However, I tried extracting the java.exe command contained in the mvn.bat file and tried using that directly, but got the same issue.
关于为什么会发生这种情况的任何想法吗?
Any thoughts about why this might be happening ?
自动运行"条目的值是:cd /d "c:\dev"
Value of the Autorun entry is : cd /d "c:\dev"
错误消息如下:
java.lang.RuntimeException: Error writing to file: some-dir/target/generated-resources/stuff.xmlwith the following error: Couldn't create dir: some-dir\target\generated-resources at com.test.build.TestFileCreation.createDirectoryTest
Error message is as follows:
java.lang.RuntimeException: Error writing to file: some-dir/target/generated-resources/stuff.xmlwith the following error: Couldn't create dir: some-dir\target\generated-resources at com.test.build.TestFileCreation.createDirectoryTest
正如@NilsH所建议的,我已经确认 当前工作目录 在两种情况下都是相同的.
As @NilsH suggested, I've confirmed that the current working directory in both the cases is the same.
已添加 maven-surefire-plugin的forkMode设置为never.无论是否存在注册表黑客,此配置文件都会使测试通过.
Added a maven profile which sets maven-surefire-plugin's forkMode to never. This profile causes the test to pass irrespective of whether the registry hack is there or not.
推荐答案
当surfire插件在分支环境中执行测试时,它将启动一个新的cmd进程.对于这种环境,注册表黑客会将工作目录设置为"c:\ dev",然后从内部启动JVM.
When the surfire plugin execute the test in a forked environment, it starts a new cmd process. For this environment the registry hack will set the working directory to "c:\dev" and the JVM is started from within.
parent.exists()
根据启动JVM的目录解析路径.这意味着测试将检查文件"C:/dev/some-dir/target/generated-resources/stuff.xml"的存在.
Resolves the path against the directory from which the JVM was started. Which means the test checks the presence of file "C:/dev/some-dir/target/generated-resources/stuff.xml".
parent.getAbsoluteFile().exists()
这将检查文件的绝对名称(即您希望检查的文件)的存在.
This checks the presence of the file with it's absolute name, the one you expected to check.
另请参见针对此JDK错误的评估注释
4483097:getAbsoluteFile()返回的文件可能未引用原始文件
see also the EVALUATION comment for this filed JDK bug
4483097 : File returned by getAbsoluteFile() may not refer to the original file
这篇关于为什么此autorun-cmd注册表黑客会影响Java/Maven进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!