machinezhou machinezhou - 10 months ago 107
Java Question

how to create a maven project in intellj with local archetype-catalog.xml

when I create a maven project in intellj, and because of network intellj cannot get "archetype-catalog.xml" from "". So I dowload it to ".m2\repository\org\apache\maven\archetype\archetype-catalog\2.4" manually without choice and in the other hand I try to change the vm options like below:
enter image description here

The question is every time I create a new project this setting just gone. So do I just have to add the "-DarchetypeCatalog=local" every time?
As you can see this is the 14th demo, how can I solve this problem? By the way If I use command line to generate new project it will generate a whole nice project with a /resources directory.

Answer Source

Option 0 : Intellij Specific

To setup that property as the default so that it gets picked up by all new projects :

File -> Other Settings -> Default Settings

And then do the same thing (i.e. Build Tools -> Maven -> Runner). After this any projects created from this point on, will inherit that JVM arg.

The remaining options below are IDE agnostic.

The following options are based on

Option 1: Environment var MAVEN_OPTS

How about setting the following environment variable ?

MAVEN_OPTS = "-DarchetypeCatalog=local"

Option 2: Directly editing the shell script (shudder!)

The other would be to edit mvn.bat or directly to add that property in.

Option 3: Creating a mavenrc file

I noticed the following in v. 3.3.9 of the maven shell script:

 # Optional ENV vars
 # -----------------
 #   M2_HOME - location of maven2's installed home dir
 #   MAVEN_OPTS - parameters passed to the Java VM when running Maven
 #     e.g. to debug Maven itself, use
 #       set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
 #   MAVEN_SKIP_RC - flag to disable loading of mavenrc files
 # ----------------------------------------------------------------------------

 if [ -z "$MAVEN_SKIP_RC" ] ; then

   if [ -f /etc/mavenrc ] ; then
     . /etc/mavenrc

   if [ -f "$HOME/.mavenrc" ] ; then
     . "$HOME/.mavenrc"


So you could put that property in either /etc/mavenrc or in ~/.mavenrc and make sure that MAVEN_SKIP_RC is not set.