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?

marc3l
  • 2,525
  • 7
  • 34
  • 62

4 Answers4

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>
neohope
  • 1,822
  • 15
  • 29
Janet
  • 772
  • 9
  • 13
  • In my case the error message said "(Is a directory)" instead of "(Access denied)", but this solution worked too. – Alex R Feb 27 '18 at 04:45
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.

p3consulting
  • 2,721
  • 2
  • 12
  • 10
  • 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. – gwnp Sep 15 '17 at 15:33
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.

jmarkmurphy
  • 11,030
  • 31
  • 59
vudangngoc
  • 128
  • 2
  • 6
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.

Sammy Cakes
  • 162
  • 2
  • 11