Writing to a file via Files write gives a AccessDeniedException exception - maven

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 ?

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);

Related

Jenkins throws an exception: build step 'invoke top-level maven targets' marked build as failure

Jenkins throws the following error:
[WARNING] The requested profile "singleflow" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project factor-esb-autotest: Fatal error compiling: invalid target release: 10 -> [Help 1]
[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/MojoExecutionException
build step 'invoke top-level maven targets' marked build as failure
My POM https://pastebin.com/xeb5Mpcb
At first I thought that the error was due to the fact that in the jenkins global settings the version does not match the plugin (3.8.1), I set it to "Install from Apach" 3.8.1 but it still does not work. What could be the reason ?
Maven in global setting
There must be a configuration for maven-compiler-plugin (<release>10</release>) or a property like <maven.compiler.release>10</maven.compiler.release>
The commented upgrade of JUnit is unrelated to the problem.
Apart from that such information that you have update pom should be part of the question up-front

Build Failed in Azure devops

I'm beginner for this in azure devops.
I'm trying to build with maven, but I got the following error that I don't understand :
[ERROR] Failed to execute goal org.codehaus.mojo:cobertura-maven-plugin:2.7:instrument (package-9af52907-6506-4b87-b16a-9883edee41bc) on project gs-spring-boot: Execution package-9af52907-6506-4b87-b16a-9883edee41bc of goal org.codehaus.mojo:cobertura-maven-plugin:2.7:instrument failed: Plugin org.codehaus.mojo:cobertura-maven-plugin:2.7 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:0 at specified path /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/../lib/tools.jar -> [Help 1]
[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/PluginResolutionException
You are missing tools.jar in your JDK/JRE. Make sure your JDK version on Azure Pipeline. It seems Cobertura doesn't support Java 1.8 and later:
https://github.com/mojohaus/cobertura-maven-plugin/issues/30
https://github.com/mojohaus/cobertura-maven-plugin/issues/21
So, switch to JaCoCo.

Feature installation error wmqjmsclient-1.1

Feature installation error:
Trying to install the JMS-MQ by enabling this wmqjmsclient-1.1 or wmqjmsclient-2.0 feature as per documentation. Both versions are giving the same error, please let me know how can I install/enable this feature.
[ERROR] Failed to execute goal io.openliberty.tools:liberty-maven-plugin:3.3.4:run (default-cli) on project CC: CWWKF1299E: The following features could not be obtained: wmqjmsclient-1.1. Ensure that the features are valid for Open Liberty. -> [Help 1]
[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/MojoExecutionException
wmqJmsClient isn't available in Open Liberty, only WebSphere Liberty. To use MQ with Open Liberty, you can create a resourceAdapter element like in this example (https://github.com/epomatti/openliberty-jms-mq-example/blob/47171bec7ef8a1e701ae363293a6cfd6a9bd5b32/liberty/server.xml#L12)
<resourceAdapter id="wmqjmsra"
location="${server.config.dir}/wmq.jmsra.rar" />
Make sure you choose an id other than wmqJms like the example, as there can be issues. You'll use that name to specify the properties, like that same example file:
<jmsQueue id="jms/queue1" jndiName="jms/queue1">
<properties.wmqjmsra baseQueueManagerName="QM1"
baseQueueName="DEV.QUEUE.1" />
</jmsQueue>
Make sure to enable the jms-2.0 feature itself if you don't have any other features pulling it in.

org.elasticsearch.common.transport.InetSocketTransportAddress not found on Elasticsearch 6

My code is working fine in elasticsearch 5 but when I have upgraded from 5 to 6 then. it is showing
org.elasticsearch.common.transport.InetSocketTransportAddress not found
complete stack trace:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project elastic-store: Compilation failure
[ERROR] /home/elastic/elastic-store/src/main/java/com/qw/psence/store/es/common/ESClient.java:[12,42] cannot find symbol
[ERROR] symbol: class InetSocketTransportAddress
[ERROR] location: package org.elasticsearch.common.transport
[ERROR] -> [Help 1]
[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/MojoFailureException
[ERROR]
can anyone help me to resolve this problem?
Note: Elaticsearch jar is fine.
Elastic search 6.0 has removed InetSocketTransportAddress class. I have solved this By replacing InetSocketTransportAddress class with TransportAddress class.
// on startup
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new TransportAddress(InetAddress.getByName("host1"), 9300))
.addTransportAddress(new TransportAddress(InetAddress.getByName("host2"), 9300));
// on shutdown
client.close();
There are many solutions offered to the problem, but I was getting this error because, as I was trying to make a basic elasticsearch configuration with SpringBoot:
I forgot to start elasticsearch...
:facepalm:
So, just:
open command line at bin folder in your Elasticsearch installation directory*
type elasticsearch
press Enter
To make sure it works, open http://localhost:9200/ in your browser. You should get a JSON response containing name, cluster_name, elasticsearch version etc.
*(On Windows) Open ES_INSTALLATION_DIR\elasticsearch-x.x.x\bin folder, hold Shift key, right click on the folder area and from the drop-down menu select Open command window here.
In my case the issue was conflicting version of the elasticsearch that was pulled into my project by the spring-boot-dependencies. If your pom does not inherit from the spring-boot-starter-parent but instead uses dependencyManagement section to import spring-boot-dependencies and you need an older version of the elasticsearch on the classpath then here is the solution: InetSocketTransportAddress. Always run mvn -Dverbose=true help:effective-pom and inspect effective pom for conflicts. -Dverbose=true is critical here. It allows to see where the unwanted dependency is coming from.

Maven says archetype does not exist

I am trying to create a JPA based project using Maven and eclipse. I tried using the jpa-maven-archetype from create new maven project in the eclipse project creation, but it shot back this error
Could not resolve archetype com.rfc.maven.archetypes:jpa-maven-archetype:RELEASE from any of the configured repositories.
Could not resolve artifact com.rfc.maven.archetypes:jpa-maven-archetype:pom:RELEASE
Failed to resolve version for com.rfc.maven.archetypes:jpa-maven-archetype:pom:RELEASE: Could not find metadata com.rfc.maven.archetypes:jpa-maven-archetype/maven-metadata.xml in local (/home/sebastian/.m2/repository)
Failed to resolve version for com.rfc.maven.archetypes:jpa-maven-archetype:pom:RELEASE: Could not find metadata com.rfc.maven.archetypes:jpa-maven-archetype/maven-metadata.xml in local (/home/sebastian/.m2/repository)
Basically the eclipse plugin is looking into my local repositories instead of remote ones. So I tried going the command line and explicitly specifying the remote repository with the following command
mvn org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create \
-DgroupId=com.something -DartifactId=jpaexample \
-DarchetypeArtifactId=jpa-maven-archetype \
-DarchetypeVersion=RELEASE \
-DremoteRepositories=http://maven.rodcoffin.com/repo \
-DinteractiveMode=false
And I got this error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create (default-cli) on project standalone-pom: Error creating from archetype: Error attempting to download archetype. Error downloading. Failed to resolve version for org.apache.maven.archetypes:jpa-maven-archetype:jar:RELEASE: Could not find metadata org.apache.maven.archetypes:jpa-maven-archetype/maven-metadata.xml in local (/home/sebastian/.m2/repository)
[ERROR] org.apache.maven.archetypes:jpa-maven-archetype:jar:RELEASE
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] id0 (http://maven.rodcoffin.com/repo, releases=true, snapshots=true)
[ERROR] -> [Help 1]
[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/MojoExecutionException
It seems that repo maven.rodcoffin.com/repo is not working, or there is something wrong with my maven setup. I am not sure which one, if some one could give me pointers on where to search for, that would be helpful.
Also if repo maven.rodcoffin.com/repo is not working. What are my other options to create a JPA archetype project. Do I have to make a simple maven project and then convert it to a JPA as shown here.
EDIT: I just weaseled out of the problem by creating a maven quick type achetype and then using the persistence.xml for my project.
So just ignore this question.

Resources