java 无法使用 Maven 打包 Web 应用程序复制工件或文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26862689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to copy artifact or file with maven packaging a web application
提问by Marcel H?ll
I have a problem packaging a web application based on vaadin. I have two projects in my workspace called project A and project B. Project A is referencing B and the dependencies are resolven within the workspace and degub mode correctly, by adding the project to the classpath.
我在打包基于 vaadin 的 Web 应用程序时遇到问题。我的工作区中有两个项目,分别称为项目 A 和项目 B。项目 A 正在引用 B,并且通过将项目添加到类路径,在工作区和调试模式中正确解析了依赖项。
Now if I try to maven package, I always get the error
现在如果我尝试 maven 包,我总是得到错误
Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project A: Failed to copy file for artifact [com.dscsag.dscxps:ProjectB:jar:0.0.1-SNAPSHOT:compile]: C:\some_path\target\classes (Access is denied) -> [Help 1]
What should I do?
我该怎么办?
采纳答案by vudangngoc
It seems to relate with security because the log said "(Access is denied)". Maybe the output jar of project B exists and there are some processes still reading from it, so that you cannot overwrite the output file. Or maven doesn't have the appropriate privilege to write the output file to the class folder.
它似乎与安全有关,因为日志上写着“(访问被拒绝)”。可能是项目B的输出jar存在,还有一些进程还在读取,无法覆盖输出文件。或者 maven 没有适当的权限将输出文件写入类文件夹。
回答by Janet
I had the same error message before. In pom.xml I changed maven-war-plugin version from 2.3 to 2.6, then the project was built successfully.
我之前也有同样的错误信息。在pom.xml中我把maven-war-plugin的版本从2.3改成了2.6,项目就搭建成功了。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
</plugin>
回答by p3consulting
This has nothing to do with security: under Windows, this problem occurs when a process doesn't "close" correctly its usage of a folder. We got the problem with apt-maven-plugin: in a complex multi-modules project, when a module using this plug-in, is then later referenced in an über jar building pom, then we got this error during the build of the über jar on the target/classes folder of the module using apt-maven-plugin. When resuming the build (mvn params -rf :offending_module), the problem disappears because the Maven process launching the apt-maven-plugin is dead, thus the lock of the folder is released.
这与安全无关:在 Windows 下,当进程未正确“关闭”其对文件夹的使用时,就会出现此问题。我们遇到了 apt-maven-plugin 的问题:在一个复杂的多模块项目中,当一个使用这个插件的模块后来在一个 über jar 构建 pom 中被引用时,我们在构建 über 的过程中遇到了这个错误使用 apt-maven-plugin 在模块的 target/classes 文件夹中创建 jar。恢复构建时(mvn params -rf :offending_module),问题消失,因为启动apt-maven-plugin的Maven进程已经死亡,文件夹的锁被释放。
Very annoying to say the least.
至少可以说很烦人。
回答by Sammy Cakes
In my experience, in the Maven plugin doing the copying (artifact maven-resources-plugin for me), the outputDirectoryelement was the issue, because I just had a slash as the output directory. I think this was causing Maven to try to copy this to C:/, and I need admin access to place files in C:/. Changing the outputDirectory to ${basedir}/target/resources got rid of this error.
根据我的经验,在执行复制的 Maven 插件中(对我来说是工件 maven-resources-plugin),outputDirectory元素是问题所在,因为我只有一个斜杠作为输出目录。我认为这导致 Maven 尝试将其复制到 C:/,并且我需要管理员访问权限才能将文件放在 C:/ 中。将 outputDirectory 更改为 ${basedir}/target/resources 摆脱了这个错误。