Maven / Eclipse外部jar故障排除

时间:2014-02-25 13:18:58

标签: java eclipse jsp maven jar

我的问题是:如何将外部jar库添加到jsp / maven / eclipse项目中? 第二个问题;如果我的问题是,我怀疑,我的pom.xml文件中的语法错误;什么是正确的?

我是一名经验丰富的经验丰富的Java开发人员,我正在寻求将我的专业知识扩展到Servlets和jsp编程。我正在试验这个。

我已经帮助建立了一个maven3 / eclipse(kepler)工作站,我已成功完成了几个基础教程。但是,我遇到了使用外部.jar来处理我的代码时遇到的严重困难。我尝试了几种解决方案。

  1. 在线提供的一个防弹解决方案就是将我的jar放入WEB-INF / lib,并通过<%@ page import = ...导入它们。 导入适用于已包含的包,即Math等。它不适用于lib-folder中的外部jar。构建路径配置为普通的eclipse java项目。

  2. 在怀疑我没有指定我正在使用maven之后,在搜索解决方案时,这确实是一个重要的细节,我发现了很多关于pom.xml文件的不同建议。依赖关系和存储库是流行语。我尝试了一些不同的复制粘贴解决方案,但现在我的项目甚至不再构建了。当我尝试启动jetty服务器并构建项目时,这是我的错误消息:

    H:\projects\xxx-releaseplan>mvn jetty:run
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building xxx-releaseplan Maven Webapp 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] >>> jetty-maven-plugin:8.1.13.v20130916:run (default-cli) @ xxx-releaseplan >>>
    [WARNING] The POM for com.xxx.mrpb.model.jar:com.xxx.mrpb.model.jar:jar:1.0 is missing, no dependency information availabl
    e
    [WARNING] The POM for com.xxx.mrpb.viewmodel.jar:com.xxx.mrpb.viewmodel.jar:jar:1.0 is missing, no dependency information
    available
    [WARNING] The POM for servlet-api-2.5.jar:servlet-api-2.5.jar:jar:2.5 is missing, no dependency information available
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.299s
    [INFO] Finished at: Tue Feb 25 13:47:26 CET 2014
    [INFO] Final Memory: 2M/61M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal on project xxx-releaseplan: Could not resolve dependencies for project com.xxx.releaseplan
    :xxx-releaseplan:war:1.0-SNAPSHOT: The following artifacts could not be resolved: com.xxx.mrpb.model.jar:com.xxx.mrpb.mode
    l.jar:jar:1.0, com.xxx.mrpb.viewmodel.jar:com.xxx.mrpb.viewmodel.jar:jar:1.0, servlet-api-2.5.jar:servlet-api-2.5.jar:jar:
    2.5: Failure to find com.xxx.mrpb.model.jar:com.xxx.mrpb.model.jar:jar:1.0 in http://repo.maven.apache.org/maven2 was cach
    ed in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updat
    es are forced -> [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/DependencyResolutionException
    H:\projects\xxx-releaseplan>
    
  3. 我的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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>dk.sdc.releaseplan</groupId>
        <artifactId>sdc-releaseplan</artifactId>
        <packaging>war</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>sdc-releaseplan Maven Webapp</name>
        <url>http://maven.apache.org</url>
        <dependencies>
            <dependency>
                <groupId>dk.sdc.mrpb.model.jar</groupId>
                <artifactId>dk.sdc.mrpb.model.jar</artifactId>
                <version>1.0</version>
                <scope>compile</scope>
                <type>jar</type>
            </dependency>
            <dependency>
                <groupId>dk.sdc.mrpb.viewmodel.jar</groupId>
                <artifactId>dk.sdc.mrpb.viewmodel.jar</artifactId>
                <version>1.0</version>
                <scope>compile</scope>
                <type>jar</type>
            </dependency>
            <dependency>
                <groupId>servlet-api-2.5.jar</groupId>
                <artifactId>servlet-api-2.5.jar</artifactId>
                <version>2.5</version>
                <scope>compile</scope>
                <type>jar</type>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <build>
            <finalName>sdc-releaseplan</finalName>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
            <plugins>
                <!--<plugin> <groupId>ro.isdc.wro4j</groupId> <artifactId>wro4j-maven-plugin</artifactId> 
                    <version>${wro4j.version}</version> <executions> <execution> <goals> <goal>jshint</goal> 
                    </goals> </execution> </executions> <configuration> <options>devel,evil,noarg</options> 
                    </configuration> </plugin> -->
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>initialize</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <tasks>
                                    <echo>********************************************</echo>
                                    <echo>***** This project REQUIRES Maven 3.0+ *****</echo>
                                    <echo>********************************************</echo>
                                    <echo>mvn jetty:run - Running as un-assembled webapp</echo>
                                    <echo>mvn jetty:run-war - Running as assembled webapp</echo>
                                </tasks>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <!-- Jetty Version: 8.x Home: Eclipse, Codehaus Java Version: 1.6 Protocols: 
                        HTTP/1.1 RFC2616, WebSocket, SPDY Servlet Version: 3.0 JSP Version: 2.1 http://wiki.eclipse.org/Jetty -->
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <version>8.1.13.v20130916</version>
                    <configuration>
                        <webAppConfig>
                            <contextPath>/</contextPath>
                        </webAppConfig>
                        <scanIntervalSeconds>1</scanIntervalSeconds>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    

1 个答案:

答案 0 :(得分:2)

错误

The following artifacts could not be resolved

表示jar文件在存储库位置不可用:http://repo.maven.apache.org/maven2

这是在M2_HOME的settings.xml中配置的。检查仓库文件的版本是否在回购中可用。

如果您可以重新检查相关性是否可用,请检查您的互联网连接以下载该内容。

如果下载了jar文件,请检查users/.m2/repository/<your artifact path>以检查它是否已正确下载。