zoukankan      html  css  js  c++  java
  • Eclipse maven问题汇总

    在使用eclipse+maven的过程中,遇到一系列问题,先汇总记录如下:

    1. 在java工程中,缺少Maven依赖:

    image

    这个问题比较棘手,一般都对eclispe的工程结构不是很了解,后来经过长时间的排查,发现在工程路径下有一个.classpath文件,正常情况下,这个文件是这个样子:

    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
        <classpathentry kind="src" path="src/main/java"/>
        <classpathentry kind="src" path="src/test/java"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
            <attributes>
                <attribute name="owner.project.facets" value="maven.deps"/>
            </attributes>
        </classpathentry>
        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
        <classpathentry kind="lib" path="E:/CVS/FileIO/lib/sec.jar"/>
        <classpathentry kind="output" path="target/classes"/>
    </classpath>

    如果在第一张图中,没有Maven dependencies,那么就是因为.classpath文件中 没有配置org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER, 如果出现这中情况,可以在工程路径下的.classpath文件中加入这几行:

    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
            <attributes>
                <attribute name="owner.project.facets" value="maven.deps"/>
            </attributes>
        </classpathentry>

    然后重启eclipse,就可以正常的看到maven dependencies了。这种解决方法针对标准版本的eclispe,比如Eclispe for Java EE Developer.

    image

    如果是商业版本的eclipse,比如MyEclipse 2015有更方便的解决方案:

    image

    image

    在MyEclipse Project Facets中,选择Maven Support-Dependencies Only,就可以将maven dependencies加入到工程中:

    image

    2. 第二个问题是外部安装maven,并且选择安装源和m2路径的设置:

    下载好apache-maven:

    image

    解压:

    image

    在我的电脑中设置,M2_HOME环境变量:

    3e21951137434e8caf82e6543427b251

    在path中添加Maven的bin:

    %M2_HOMEin;

    在命令行中可以看到:

    image

    在eclipse中,设置刚才安装的maven:

    image

    在maven的安装路径的conf目录下有settings.xml:

    image

    <settings 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/settings-1.0.0.xsd">  
     <mirrors>
        <mirror>
          <id>CN</id>
          <name>OSChina Central</name>                                                                                                                       
          <url>http://maven.oschina.net/content/groups/public/</url>
          <mirrorOf>central</mirrorOf>
        </mirror>
      </mirrors>
      
      <localRepository>D:Javam2
    epository</localRepository>
    </settings>

    然后在eclipse中设置,选择刚才设置好的settings.xml文件,可以看到local repository中的路径变成settings.xml中设置的本地路径:

    image

    3. eclipse中soruce path和output dir出现问题,导致工程自己找不到自己的包

    image

    image

    image

  • 相关阅读:
    2019-04-02 cast and covert
    2019-04-01 为什么零售业务流行起来了?
    2019-04-01 银行的零售业务和对公业务
    服务器推送更新
    webpack 大概
    webpack
    react Hooks
    react 表单受控和非受控
    eslint规则
    react系列笔记:第三记-redux-saga
  • 原文地址:https://www.cnblogs.com/justinzhang/p/4941839.html
Copyright © 2011-2022 走看看