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.

Community
  • 1
  • 1
andPat
  • 4,153
  • 7
  • 24
  • 36
  • possible duplicate of [How to run maven from java?](http://stackoverflow.com/questions/5141788/how-to-run-maven-from-java) – Joe Sep 23 '14 at 13:15
  • No I don't think it's a duplicate, see my last edit. – andPat Sep 23 '14 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). – andPat Sep 24 '14 at 08:21

1 Answers1

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. :-)

johnstosh
  • 335
  • 1
  • 5