-2

I'm creating a maven plugin and I need to write a new file in the project directory.

For some reason when I try to create a new file I get the AccessDeniedException.

StackTrace:

[ERROR] Failed to execute goal org.ofx:ofx-maven-plugin:1.0-SNAPSHOT:generateScreensEnum (default) on project preloader: Execution default of goal org.ofx:ofx-maven-plugin:1.0-SNAPSHO
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

c:\devl\work\preloader>

It is a none existing file so It should not be a locked resource case. I also tried writing to a different folder (not the project folder) just in case to see if it solves it, it does not.

My code:

Files.write(enumLocation, lines, Charset.defaultCharset(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);

Any ideas ?

David Limkys
  • 4,907
  • 5
  • 26
  • 38
  • 1
    Showing the code you have written would help – Ryan J Oct 18 '14 at 16:49
  • Still not enough details. Show us all the code, including the code that builds the path to the file to write (and tell us what that code is supposed to do and what it actually does). – Jeffrey Bosboom Oct 18 '14 at 17:59
  • Like is said, it does not matter what the path of the file to write is, i tried "c:\\temp" and I get the same error, I have nothing more to elaborate on, I'm just trying to save a file to any location on the disk. – David Limkys Oct 18 '14 at 18:17
  • @DavidLimkys What's before the first `[ERROR]` line? Have you taken Maven's proposal? `mvn ... -e -X` – Gerold Broser Oct 18 '14 at 18:32

1 Answers1

0

Found the problem, need to add a StandardOpenOption.WRITE, option if the file does not exist.

Files.write(enumLocation, lines, Charset.defaultCharset(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
David Limkys
  • 4,907
  • 5
  • 26
  • 38