1

I get the following error when I want to run "mvn deploy" in my project:

[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ JImp ---
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.6/plexus-utils-1.5.6.jar
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.6/plexus-utils-1.5.6.jar (245 KB at 188.8 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.973 s
[INFO] Finished at: 2014-12-16T10:35:39+01:00
[INFO] Final Memory: 24M/226M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project JImp: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [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

My POM-File looks like that:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>JImp</groupId>
    <artifactId>JImp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.6.0</version>
        </dependency>
        <dependency>
            ....
        </dependency>
    </dependencies>
</project>

In my project I am using a bunch of jar-Files (like SWT, Log4j and so on, but also own libraries). But all of these are added to my local repository (my own libs I added by mvn install:install-file ..) and in the depedencies of my POM.. In Eclipse my Project "knows" all imports, the code looks fine, has no errors or something like that..

If I only run

mvn package

and then executing my jar

java -cp target\JImp-0.0.1-SNAPSHOT.jar de.my.path.JImp

he throws a ClassNotFoundException because he couldn't find a class of my own lib.. But this lib is added to the local repository and to the depedency in my POM-File.. :/

Maybe you could help me..!!

I appreciate your help very much!

mrbela
  • 4,477
  • 9
  • 44
  • 79

1 Answers1

1

for mvn deploy issue

You need to provide repository address where you want to deploy you arfifact in pom.xml like below

<distributionManagement>
  <repository>
    <id>mycompany-repository</id>
    <name>MyCompany Repository</name>
    <url>your repository url</url>
  </repository>
</distributionManagement>

To run maven artifact jar, you need to use mvn exec command, then only it includes all jars mentioned in pom.xml in your classpath. See example below

mvn exec:java -Dexec.mainClass="de.my.path.JImp"
Adi
  • 2,364
  • 1
  • 17
  • 23
  • I found: "Maven will first attempt to use a local copy of the specified artifact. If that artifact does not exist in the local repository, it will then attempt to download from a remote repository" (http://maven.apache.org/pom.html#Repositories) Why do I have to define a repository when I want to use mvn deploy? – mrbela Dec 16 '14 at 10:20
  • And is it enough to invoke mvn package or do I have to run the whole default life-cylce (validate, compile, test, package, integration-test, verify, install, deploy) by invoking mvn deploy – mrbela Dec 16 '14 at 10:23
  • 1
    `mvn deploy` command get used to upload ***your artifact*** to remote repository. If you just want to add in local repository, then `mvn install` will do. – Adi Dec 16 '14 at 10:24
  • 1
    for your second question, it runs as life cycle, so when you execute in lifecycle phase, say `package`, all phases before it gets automatically executed. – Adi Dec 16 '14 at 10:25
  • Thank you very much for your help!!! To my second question: Which phase should be invoked by default? I know, it depends on what I want, but are the phases "integration-test" and "verify" usefull to find errors or something like that? I think that I don't need the phases "install" and "deploy", because I don't use my artifact in other projects (locally and from my remote repository) – mrbela Dec 16 '14 at 10:41
  • as you said, it depend on need, but i found `package` most helpful while doing local development, it cleans project, compile all resources, executes all unit tests and then builds jar artifact. – Adi Dec 16 '14 at 10:46
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/66987/discussion-between-adi-and-user2438518). – Adi Dec 16 '14 at 10:59