`
xfxlch
  • 浏览: 165997 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

how to fix "org.hamcrest.CoreMatchers.containsString cannot be resolved"

    博客分类:
  • Java
阅读更多
背景:
山姆大叔比较喜欢用一些新的技术和新的特性,最近在junit test的代码中,用到了containsString(String subString) 方法。
这个方法主要是用来创建一个包含了subString字符串的Matcher,通常的用法是:
assertThat("myStringOfNote", containsString("ring"));
即:assert一个信息,如果containsString 返回的Matcher中包含于“myStringOfNote”字符串中, 那么这个就不会抛异常;否则就会抛出类似:
 java.lang.AssertionError: 
 Expected: (a string containing "color" or a string containing "colour")
      got: "Please choose a font"

具体到这个assert的用法可以更多地去看官网的例子。
我这里是要说的是:同样的代码,我直接get latest revision 到我本地的时候,别人的可以跑,但是在我自己这里就不能编译,出现方法找不到的错误:
The import org.hamcrest.CoreMatchers.containsString cannot be resolved


解决方案:
我找到了同事的代码,对比看了,都是一样的。 刚开始以为是jdk版本不一致导致的问题。
方案1: 于是就改成了我同事一样版本的jdk,还是不能解决。
方案2: 去找到相应的jar,于是我找到hamcrest-all-1.3.jar,也都是有的。但是在我搜索hamcrest的时候,我的同事的jar包依赖来有一个:hamrest-core:1.3 的jar。如下:


而我的pom依赖树里没有这个jar,我很苦恼,为什么会出现这样的情况,而是我把本地repository的junit-4.11.jar删除掉,然后重新从服务器上拿到这个jar,这一次果然能拿到hamrest-core的依赖的。成功解决这个问题。



----EOF----

  • 大小: 11.4 KB
分享到:
评论
1 楼 xfxlch 2015-10-17  
http://blog.csdn.net/longaohun/article/details/6782046

相关推荐

    解决The type org.springframework.dao.support.DaoSupport cannot be resolved.bao报错

    在开发Spring框架相关的Java应用时,可能会遇到"The type org.springframework.dao.support.DaoSupport cannot be resolved"的错误提示。这个错误通常意味着编译环境无法找到`DaoSupport`类,这是Spring DAO模块中的...

    httpcomponents-client-4.5.5-bin和src_20180518.zip

    > ★The type org.apache.http.NameValuePair cannot be resolved. It is indirectly referenced from required .class > ★BasicNameValuePair cannot be resolved to a type > ★HttpPost cannot be resolved to a...

    org.apache.poi jar包

    org.apache.poi JAR包,解决个人的 import org.apache.commons.beanutils.PropertyUtilsBean; import org.apache.commons.lang.StringUtils;..."The import org.apache.poi cannot be resolved"的问题

    The import com.loopj cannot be resolved 的解决方案

    在编程过程中,我们时常会遇到各种编译错误,其中一种常见的问题是"The import com.loopj cannot be resolved"。这个错误信息表明你的项目无法找到`com.loopj`包,这通常是由于缺少必要的库文件导致的。`com.loopj`...

    org.apache.poi JAR包

    org.apache.poi JAR包,解决个人的 import org.apache.commons.beanutils.PropertyUtilsBean; import org.apache.commons.lang.StringUtils;..."The import org.apache.poi cannot be resolved"的问题

    org.apache.commons.codec包

    解决经常遇到的The import org.apache.commons.codec cannot be resolved问题,只需导入文件中的commons-codec-1.11.jar就可以,如和导入包就不赘述了。

    导入工程的“The import android cannot be resolved”错误解决方法

    在进行Android应用开发时,尤其是使用Eclipse作为集成开发环境(IDE)时,开发者可能会遇到一个常见的错误:“The import android cannot be resolved”。这个错误通常发生在尝试导入或打开一个已存在的Android项目...

    commons-lang3-3.1.jar

    当你在项目中遇到"The import org.apache.commons.lang3 cannot be resolved"的错误时,通常是因为缺少了这个库的引用,导致你的代码无法找到所需的类。 `org.apache.commons.lang3`是该库的主要包名,其中包含了...

    java eclipse 出现 xxx cannot be resolved to a type 错误解决方法

    Java Eclipse 出现 "xxx cannot be resolved to a type" 错误解决方法 Java Eclipse 是一个功能强大且广泛使用的集成开发环境(IDE),但是在使用过程中可能会出现各种错误信息,例如 "xxx cannot be resolved to a...

    org.apache.commons.dbcp.BasicDataSource的解决方法

    在处理`org.apache.commons.dbcp.BasicDataSource`时,可能会遇到一些常见问题,如配置错误、连接泄漏、性能问题等。下面我们将详细探讨这些问题及其解决方案。 首先,`BasicDataSource`是DBCP库中的核心类,它实现...

    jar.zip解决The import javax.crypto cannot be resolved

    然而,有时在开发过程中,我们可能会遇到"The import javax.crypto cannot be resolved"这样的错误提示,这意味着编译器无法找到这个包或者其依赖的库。这通常是由于JDK的默认配置中未包含某些安全相关的扩展,如...

    estableRuntimeException cannot be resolved 解决

    在这种情况下,"org.apache.commons.lang.exception.NestableRuntimeException cannot be resolved" 错误表明开发环境中缺少了Apache Commons Lang库的一个特定版本,即`NestableRuntimeException`类。这个类存在于...

    rsslib4j-0.2.jar jar包,解决java报错找不到资源包问题 The import org.gnu cannot be resolved

    rsslib4j-0.2.jar jar包,解决java报错找不到资源包问题 The import org.gnu cannot be resolved。 报错 import org.gnu.stealthp.rsslib.*; RSSChannel、RSSException、RSSHandler、RSSItem、RSSParser

    apache-ant-1.8.2.jar

    The type org.apache.tools.ant.Task cannot be resolved. It is indirectly referenced from required .class files错误....., 解决办法:在工程中加入此jar包

    org.apache.commons.lang3.StringUtils.jar

    java获取客户端ip(经过多次代理)提示StringUtils cannot be resolved 需要先 import org.apache.commons.lang3.StringUtils; /* 内含 common-lang3.jar commons-lang3-3.9-bin.zip commons-lang3-3.9-src.zip ...

    详解 问题:HttpServlet cannot be resolved to a type

    在开发Java Web应用程序时,你可能会遇到一个常见的错误:“HttpServlet cannot be resolved to a type”。这个错误通常发生在尝试使用`HttpServlet`类时,而Eclipse IDE无法找到对应的类定义。`HttpServlet`是Java ...

    pentaho-aggdesigner-algorithm-5.1.5-jhyde.tar

    解决 Cannot resolve org.pentaho:pentaho-aggdesigner-algorithm:5.1.5-jhyde jar放入D根目录执行: 以下命令加入本地maven库 mvn install:install-file -DgroupId=org.pentaho -DartifactId=pentaho-aggdesigner-...

    测试类报错Test cannot be resolved to a type-附件资源

    测试类报错Test cannot be resolved to a type-附件资源

    Maven报错: Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.0.2:resources

    idea创建Maven项目时,报错显示Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.0.2:resources,并且Maven插件内看不到 mybatis-generator。如下图: 折腾了好久发现配置放错地方了,...

    org.springframework.web.servlet-3.1.0.RELEASE

    * <p>Represents a model and view returned by a handler, to be resolved * by a DispatcherServlet. The view can take the form of a String * view name which will need to be resolved by a ViewResolver ...

Global site tag (gtag.js) - Google Analytics