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

4

10

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?

Lection answered 11/11, 2014 at 10:27 Comment(1)
deleting the generated content in the \target folder should fix the problem.Paling
E
2

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.

Expectancy answered 11/11, 2014 at 10:34 Comment(0)
L
27

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>
Lookout answered 6/11, 2015 at 17:12 Comment(1)
In my case the error message said "(Is a directory)" instead of "(Access denied)", but this solution worked too.Adolfoadolph
C
6

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.

Campanula answered 21/11, 2016 at 6:41 Comment(1)
I've come across this exact error without the folders being locked (confirmed via unlocker). Furthermore, continuing the execution with mvn install -rf :my-web does not clear the problem. I am running this via command-line, not a workspace.Poirier
E
2

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.

Expectancy answered 11/11, 2014 at 10:34 Comment(0)
L
0

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.

Leicestershire answered 28/1, 2020 at 14:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.