Failed to copy artifact or file with maven packaging a web application

27.9k Views Asked by At

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.

Now if I try to maven package, I always get the error

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?

4

There are 4 best solutions below

0
On BEST ANSWER

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.

1
On

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.

Very annoying to say the least.

1
On

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.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
</plugin>
0
On

In my experience, in the Maven plugin doing the copying (artifact maven-resources-plugin for me), the outputDirectory element 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.