Maven从Eclipse看到依赖的项目jar,但不是从命令行看到的

时间:2014-02-25 19:41:15

标签: java eclipse maven m2eclipse m2e

我在Eclipse之外构建我的maven项目时遇到了麻烦。在eclipse中,我可以毫无问题地完成它,所有依赖关系都得到了解决。

我得到的错误是它无法从依赖项目中找到jar文件:

    myuser@Laptop:~/workspace/Measurement_processor$ mvn clean -X compile        
    Warning: JAVA_HOME environment variable is not set.
    Apache Maven 3.0.4
    Maven home: /usr/share/maven
    Java version: 1.7.0_51, vendor: Oracle Corporation
    Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
    Default locale: en_IE, platform encoding: UTF-8
    OS name: "linux", version: "3.11.0-17-generic", arch: "amd64", family: "unix"
    [INFO] Error stacktraces are turned on.
    [DEBUG] Reading global settings from /usr/share/maven/conf/settings.xml
    [DEBUG] Reading user settings from /home/myuser/.m2/settings.xml
    [DEBUG] Using local repository at /home/myuser/.m2/repository
    [DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for /home/myuser/.m2/repository
    [INFO] Scanning for projects...
    [DEBUG] Extension realms for project com.mydomain:MeasurementProcessor:jar:0.0.1-SNAPSHOT: (none)
    [DEBUG] Looking up lifecyle mappings for packaging jar from ClassRealm[plexus.core, parent: null]
    [DEBUG] === REACTOR BUILD PLAN ================================================
    [DEBUG] Project: com.mydomain:MeasurementProcessor:jar:0.0.1-SNAPSHOT
    [DEBUG] Tasks:   [clean, compile]
    [DEBUG] Style:   Regular
    [DEBUG] =======================================================================
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building MeasurementProcessor 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
    [DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
    [DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
    [DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
    [DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
    [DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
    [DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
    [DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
    [DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
    [DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
    [DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
    [DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
    [DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
    [DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
    [DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
    [DEBUG] === PROJECT BUILD PLAN ================================================
    [DEBUG] Project:       com.mydomain:MeasurementProcessor:0.0.1-SNAPSHOT
    [DEBUG] Dependencies (collect): []
    [DEBUG] Dependencies (resolve): [compile]
    [DEBUG] Repositories (dependencies): [central (http://repo.maven.apache.org/maven2, releases)]
    [DEBUG] Repositories (plugins)     : [central (http://repo.maven.apache.org/maven2, releases)]
    [DEBUG] -----------------------------------------------------------------------
    [DEBUG] Goal:          org.apache.maven.plugins:maven-clean-plugin:2.3:clean (default-clean)
    [DEBUG] Style:         Regular
    [DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <directory default-value="${project.build.directory}"/>
      <excludeDefaultDirectories default-value="false">${clean.excludeDefaultDirectories}</excludeDefaultDirectories>
      <failOnError default-value="true">${maven.clean.failOnError}</failOnError>
      <followSymLinks default-value="false">${clean.followSymLinks}</followSymLinks>
      <outputDirectory default-value="${project.build.outputDirectory}"/>
      <project default-value="${project}"/>
      <reportDirectory default-value="${project.reporting.outputDirectory}"/>
      <skip default-value="false">${clean.skip}</skip>
      <testOutputDirectory default-value="${project.build.testOutputDirectory}"/>
      <verbose>${clean.verbose}</verbose>
    </configuration>
    [DEBUG] -----------------------------------------------------------------------
    [DEBUG] Goal:          org.apache.maven.plugins:maven-resources-plugin:2.3:resources (default-resources)
    [DEBUG] Style:         Regular
    [DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <encoding default-value="${project.build.sourceEncoding}">${encoding}</encoding>
      <escapeString>${maven.resources.escapeString}</escapeString>
      <filters>${project.build.filters}</filters>
      <includeEmptyDirs default-value="false">${maven.resources.includeEmptyDirs}</includeEmptyDirs>
      <outputDirectory>${project.build.outputDirectory}</outputDirectory>
      <overwrite default-value="false">${maven.resources.overwrite}</overwrite>
      <project>${project}</project>
      <resources>${project.resources}</resources>
      <session>${session}</session>
    </configuration>
    [DEBUG] -----------------------------------------------------------------------
    [DEBUG] Goal:          org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile)
    [DEBUG] Style:         Regular
    [DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <basedir default-value="${basedir}"/>
      <buildDirectory default-value="${project.build.directory}"/>
      <classpathElements default-value="${project.compileClasspathElements}"/>
      <compileSourceRoots default-value="${project.compileSourceRoots}"/>
      <compilerId default-value="javac">${maven.compiler.compilerId}</compilerId>
      <compilerReuseStrategy default-value="${reuseCreated}">${maven.compiler.compilerReuseStrategy}</compilerReuseStrategy>
      <compilerVersion>${maven.compiler.compilerVersion}</compilerVersion>
      <debug default-value="true">${maven.compiler.debug}</debug>
      <debuglevel>${maven.compiler.debuglevel}</debuglevel>
      <encoding default-value="${project.build.sourceEncoding}">${encoding}</encoding>
      <executable>${maven.compiler.executable}</executable>
      <failOnError default-value="true">${maven.compiler.failOnError}</failOnError>
      <forceJavacCompilerUse default-value="false">${maven.compiler.forceJavacCompilerUse}</forceJavacCompilerUse>
      <fork default-value="false">${maven.compiler.fork}</fork>
      <generatedSourcesDirectory default-value="${project.build.directory}/generated-sources/annotations"/>
      <maxmem>${maven.compiler.maxmem}</maxmem>
      <meminitial>${maven.compiler.meminitial}</meminitial>
      <mojoExecution>${mojoExecution}</mojoExecution>
      <optimize default-value="false">${maven.compiler.optimize}</optimize>
      <outputDirectory default-value="${project.build.outputDirectory}"/>
      <projectArtifact default-value="${project.artifact}"/>
      <showDeprecation default-value="false">${maven.compiler.showDeprecation}</showDeprecation>
      <showWarnings default-value="false">${maven.compiler.showWarnings}</showWarnings>
      <skipMain>${maven.main.skip}</skipMain>
      <skipMultiThreadWarning default-value="false">${maven.compiler.skipMultiThreadWarning}</skipMultiThreadWarning>
      <source default-value="1.5">1.7</source>
      <staleMillis default-value="0">${lastModGranularityMs}</staleMillis>
      <target default-value="1.5">1.7</target>
      <useIncrementalCompilation default-value="true">${maven.compiler.useIncrementalCompilation}</useIncrementalCompilation>
      <verbose default-value="false">${maven.compiler.verbose}</verbose>
      <mavenSession default-value="${session}"/>
      <session default-value="${session}"/>
    </configuration>
    [DEBUG] =======================================================================
    [DEBUG] Could not find metadata com.mydomain:CommonLibraries:0.0.1-SNAPSHOT/maven-metadata.xml in local (/home/myuser/.m2/repository)
    [DEBUG] Could not find metadata com.mydomain:CommonLibraries:0.0.1-SNAPSHOT/maven-metadata.xml in local (/home/myuser/.m2/repository)
    [WARNING] The POM for com.mydomain:CommonLibraries:jar:0.0.1-SNAPSHOT is missing, no dependency information available
    [DEBUG] com.mydomain:MeasurementProcessor:jar:0.0.1-SNAPSHOT
    [DEBUG]    com.fasterxml.jackson.core:jackson-databind:jar:2.2.3:compile
    [DEBUG]       com.fasterxml.jackson.core:jackson-annotations:jar:2.2.3:compile
    [DEBUG]       com.fasterxml.jackson.core:jackson-core:jar:2.2.3:compile
    [DEBUG]    org.testng:testng:jar:6.8.7:test
    [DEBUG]       junit:junit:jar:4.10:test
    [DEBUG]          org.hamcrest:hamcrest-core:jar:1.1:test
    [DEBUG]       org.beanshell:bsh:jar:2.0b4:test
    [DEBUG]       com.beust:jcommander:jar:1.27:test
    [DEBUG]       org.yaml:snakeyaml:jar:1.12:test
    [DEBUG]    de.congrace:exp4j:jar:0.3.11:compile
    [DEBUG]    joda-time:joda-time:jar:2.3:compile
    [DEBUG]    com.mydomain:CommonLibraries:jar:0.0.1-SNAPSHOT:compile
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.602s
    [INFO] Finished at: Tue Feb 25 19:22:18 GMT 2014
    [INFO] Final Memory: 5M/102M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal on project MeasurementProcessor: Could not resolve dependencies for project com.mydomain:MeasurementProcessor:jar:0.0.1-SNAPSHOT: Could not find artifact com.mydomain:CommonLibraries:jar:0.0.1-SNAPSHOT -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project MeasurementProcessor: Could not resolve dependencies for project com.mydomain:MeasurementProcessor:jar:0.0.1-SNAPSHOT: Could not find artifact com.mydomain:CommonLibraries:jar:0.0.1-SNAPSHOT
        at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:210)
        at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resolveProjectDependencies(LifecycleDependencyResolver.java:117)
        at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved(MojoExecutor.java:258)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:201)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
    Caused by: org.apache.maven.project.DependencyResolutionException: Could not resolve dependencies for project com.mydomain:MeasurementProcessor:jar:0.0.1-SNAPSHOT: Could not find artifact com.mydomain:CommonLibraries:jar:0.0.1-SNAPSHOT
        at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:189)
        at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:185)
        ... 22 more
    Caused by: org.sonatype.aether.resolution.DependencyResolutionException: Could not find artifact com.mydomain:CommonLibraries:jar:0.0.1-SNAPSHOT
        at org.sonatype.aether.impl.internal.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:375)
        at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:183)
        ... 23 more
    Caused by: org.sonatype.aether.resolution.ArtifactResolutionException: Could not find artifact com.mydomain:CommonLibraries:jar:0.0.1-SNAPSHOT
        at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:538)
        at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:216)
        at org.sonatype.aether.impl.internal.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:358)
        ... 24 more
    Caused by: org.sonatype.aether.transfer.ArtifactNotFoundException: Could not find artifact com.mydomain:CommonLibraries:jar:0.0.1-SNAPSHOT
        at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:528)
        ... 26 more
    [ERROR] 
    [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/DependencyResolutionException

这是项目的pom:         http://maven.apache.org/xsd/maven-4.0.0.xsd">             4.0.0

        <groupId>com.mydomain</groupId>
        <artifactId>MeasurementProcessor</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>

        <name>MeasurementProcessor</name>
        <url>http://maven.apache.org</url>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>

        <dependencies>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.2.3</version>
            </dependency>
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.8.7</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>de.congrace</groupId>
                <artifactId>exp4j</artifactId>
                <version>0.3.11</version>
            </dependency>
            <dependency>
                <groupId>joda-time</groupId>
                <artifactId>joda-time</artifactId>
                <version>2.3</version>
            </dependency>
            <dependency>
                <groupId>com.mydomain</groupId>
                <artifactId>CommonLibraries</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
        </dependencies>
    </project>

正如您所看到的,它依赖于com.mydomain:CommonLibraries,它有一个pom.xml,如下所示:

    <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>com.mydomain</groupId>
        <artifactId>CommonLibraries</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>


        <build>
    <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>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
                <version>1.9</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.2.3</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>1.1.1</version>
            </dependency>
            <dependency>
                <groupId>com.zaxxer</groupId>
                <artifactId>HikariCP</artifactId>
                <version>1.2.8</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.28</version>
            </dependency>
            <dependency>
                <groupId>joda-time</groupId>
                <artifactId>joda-time</artifactId>
                <version>2.3</version>
            </dependency>
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.8.7</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.7.6</version>
            </dependency>
        </dependencies>
    </project>

最终目标是让这个在jenkins上运行,但第一步是让它在终端上运行。

更新

我清理(删除)了mydomain存储库中编译源的目录,然后重新启动CommonLibraries的安装。那很有效!

之后我遇到了错误,但它们与我在主文件夹中依赖于TestNG的测试类有关。它现在有效。

1 个答案:

答案 0 :(得分:0)

为负责com.mydomain:CommonLibraries:jar:0.0.1-SNAPSHOT工件的项目运行“mvn clean install”,以便在Maven存储库中创建它。

您看到的行为是因为m2e可以直接从Eclipse项目中解析工件。