1

I made some jar files (using java and jar commands in CMD) but when I try to install them in a local directory (to use it as may local maven repository) by following command:

 mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> 

but maven gives me following error:

The goal you specified requires a project to execute but there is no POM in this directory

which means that this command needs a pom file but which pom file (do I need to repackage my code with maven again!)

Hans Z.
  • 50,496
  • 12
  • 102
  • 115
Mr.Q
  • 4,316
  • 3
  • 43
  • 40
  • @prabugp if you just want to install the jar, then, an empty pom will suffice ? Anyway, I don't see why is it necessary just to install a 3rd party artifact. – perencia May 01 '14 at 17:43
  • 1
    @perencia you're right. It's not necessary. I was misled by the error message. OP, Please see if you are bitten by this: http://stackoverflow.com/a/11199865/2231632 ? I just executed this in a non-project directory and it worked for me. There is also a typo: it's -DartifcatId and that - is missing. – Praba May 01 '14 at 17:51
  • The missing hyphen before `DartifactId` is likely to be the problem - maven is trying to treat `Dartifact....` as the goal name. – Ian Roberts Jan 15 '15 at 10:12

2 Answers2

0

first go to your maven conf/settings.xml and define your local repo location:

Repository>E:/repo2/</localRepository>

then go CMD and type:

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

NOTE: cause you don't have any pom in this case. you should define all the necessary parameters (groupid, artifactid, packaging and version) otherwise you will get an exception.

NOTE: if in your string, contains spaces you need to surround it with a double quotation ("").

Also note that you can tell the location of your local repo explicitly, by parameter (-DlocalRepositoryPath).

If the above config doesn't work you can save all your config info in a pom file and reference it explicitly like below:

mvn install:install-file -Dfile=<path-to-file>  -DpomFile=<path to pom file>
Mr.Q
  • 4,316
  • 3
  • 43
  • 40
0

I recommend not to build the jar with Java but to use maven to build and install it.

1) Setup a new simple Maven project

mvn archetype:create -DgroupId=yourProject -DartifactId=yourProjectsArtifactID -DarchetypeArtifactId=maven-archetype-quickstart

(http://maven.apache.org/plugins-archives/maven-archetype-plugin-1.0-alpha-7/examples/simple.html)

2) Place the Java source for your jar into the resulting folder: ...\yourProjectsArtifactID\src\main\java

3) If required declare the dependencies of your code which should be included in the classpath when compiling it to the POM.xml in ...\yourProjectsArtifactID. You can do so by opening it in a text editor and replicating the existing entry for each jar that you would like to have in the classpath. Change the value in the scope tag to compile or remove it.

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
</dependency>

4) Compile and install your jar

Run

mvn clean install

inside the folder in which the pom.xml resides: "...\yourProjectsArtifactID":

rob2universe
  • 7,059
  • 39
  • 54