2

I'm using Maven Java API to configure Maven in a custom Java project. In particular I need to configure some Maven settings, among which there are proxy settings. How can i do this? I googled a lot, but I found no examples on how to use Maven from Java. Can You give me an example or a guide, a snippet of code, whatever you want to clarify HOW TO USE (AND CONFIGURE) Maven by Java API, i.e from Java code?

I found this maven reference, but what do I specifically need?

Thanks in advance.

I've already seen this question, but unfortunately there is no mention on how to edit settings.xml from maven api, I suppose it is possible, but I'm not sure of it, so I asked a new question, wider than that one, how can I manage Maven from Java? settings, run, properties, whatever... is it possible?

For example, about settings management, I found this API maven-settings, it can be useful? It's "read-only" API? I guess it isn't, but I've found no way how to "write" modifications to file, there are no examples on how to use it.

3
  • possible duplicate of How to run maven from java? Commented Sep 23, 2014 at 13:15
  • No I don't think it's a duplicate, see my last edit. Commented Sep 23, 2014 at 13:37
  • I remark that in the question that, about you, is duplicated is NOT explained how to manage from Java maven settings (using some API)!! If it is not possible just ANSWER "is not possible, you are crazy thinking such thing" and I'll soon mark this question as closed, but please answer (if you can). Commented Sep 24, 2014 at 8:21

1 Answer 1

1

Well, yes, you are a bit crazy. You can take a look at some plug-ins which modify pom.xml files. For example, the versions-set facility shown here:

http://www.mojohaus.org/versions-maven-plugin/set-mojo.html

The source code for that plug-in will show you how to modify pom.xml files, but you also want to modify the settings.xml file.

All of these files are XML. Basically, you want to obtain a DOM for the .xml file. So, you can use generic XML tools to (1) read the file, (2) modify the document model, (3) write the data back to disk.

Note well: Maven caches the .xml files. You have to stop the maven executable and restart it to force it to re-read the .xml files. It sounds like you'll probably be doing this as a matter of course. :-)

Sign up to request clarification or add additional context in comments.

1 Comment

Thabk you very much for the response and to second me;) I'll try!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.