我是Gradle的新手,所以如果这个问题看起来很幼稚或简单,请原谅.
我的eclipse项目存在且运行良好,我想为我的日志记录添加Logback.在build.gradle中设置依赖项很容易...
dependencies {
groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.8.3'
// Logback dependencies
compile 'org.slf4j:slf4j-api:1.6.4'
compile 'ch.qos.logback:logback-core:1.0.3'
compile 'ch.qos.logback:logback-classic:1.0.3'
}
Run Code Online (Sandbox Code Playgroud)
...这可以让我的构建成功,但是如何才能让它更新我的eclipse项目的"Referenced Libraries"部分?换句话说,我可以让gradle更新eclipse的.classpath,为通过gradle依赖项引入的任何新库添加适当的条目吗?
就目前而言,我必须弄清楚〜/ .gradle中依赖项成为JAR文件的位置,并手工创建引用库来指向它们.育.必须有一种自动化方法.
我有一个使用了蒙戈Java驱动程序蒙戈的Java驱动程序 - 2.8.0.jar参观那里的所有记录在一个单一的集合更新任何不符合预期结构的Groovy脚本.这个脚本的作用就像一个冠军,但是我为什么要处理比集合实际拥有的记录更多的记录.或者,更准确地说,dbCursore.hasNext()迭代的记录多于集合实际拥有的记录.仅当脚本找到要更新的内容时才会出现这种情况.如果脚本在没有更新的情况下执行,则处理的总数是正确的.
hasNext()是否"重新开始"或者记录是否在迭代中移动(如果它们已被更新)?
这是代码......
static def doIt( mongo, normalizer, isDryRun ) {
def ttlProcessed = 0
def ttlCandidates = 0
def ttlUpdated = 0
def lapCount = 0;
def lapStartTime = System.currentTimeMillis();
def db = mongo.getDB( "devices" )
DBCollection dbCollection = db.getCollection( "profiles" )
DBCursor dbCursor = dbCollection.find();
while ( dbCursor.hasNext() ) {
DBObject source = dbCursor.next();
DBObject normalized = normalizer.normalize( source )
// Only update if changed...
if ( ! ( source.equals( normalized ) ) ) {
ttlCandidates++ …Run Code Online (Sandbox Code Playgroud) 除了这个简单的调用之外,我对python知之甚少: python -m json.tool {someSourceOfJSON}
请注意源文档如何排序“id”、“z”、“a”,但生成的 JSON 文档显示属性“a”、“id”、“z”。
$ echo '{ "id": "hello", "z": "obj", "a": 1 }' | python -m json.tool
{
"a": 1,
"id": "hello",
"z": "obj"
}
Run Code Online (Sandbox Code Playgroud)
我如何或可以使json.tool事物保持原始 JSON 文档中属性的顺序?
python 版本是这个 MacBookPro 附带的任何版本
$ python --version
Python 2.7.15
Run Code Online (Sandbox Code Playgroud) 我想知道Java驱动程序相当于Mongo JavaScript shell的Object.bsonsize(doc)方法是什么?例如,执行以下操作的Java代码是什么:
bobk-mbp:~ bobk$ mongo
MongoDB shell version: 2.0.4
connecting to: test
PRIMARY> use devices;
switched to db devices
PRIMARY> Object.bsonsize( db.profiles.findOne( { _id: "REK_0001" } ) );
186
PRIMARY> Object.bsonsize( db.profiles.findOne( { _id: "REK_0002" } ) );
218
PRIMARY>
Run Code Online (Sandbox Code Playgroud)
如何使用MongoDB Java驱动程序执行相同的基本用例.通过JavaDocs并不明显.
我是Scala/Play 2.1/Specs2堆栈的新手,所以如果这个问题看起来很简单,请原谅我,但我在编写规范以测试"字符串包含单词'GET'"时遇到了困难.我有一个Play 2.1 Action,它返回一个Access-Control-Allow-Methods标头值
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS
Run Code Online (Sandbox Code Playgroud)
我的规范对其他标头进行直接相等检查没有问题,但是我一直无法弄清楚如何检查GET,PUT,POST,DELETE和OPTIONS中的每一个的Access-Control-Allow-Methods标头.我期望像"必须包含("GET")这样的东西可以工作,但是IDE在这个问题上变成了红色:
type mismatch; found : org.specs2.matcher.ContainMatcher[String] required: org.specs2.matcher.Matcher[Option[String]] SessionsSpec.scala /dm2-server/test/admin line 53 Scala Problem
Run Code Online (Sandbox Code Playgroud)
我的规格看起来像......
"send 200 on OPTIONS request on valid route" in {
running(FakeApplication()) {
var fakeReq = FakeRequest("OPTIONS", "/admin/sessions")
val Some(result) = route(fakeReq)
status(result) must equalTo(OK)
header(ACCESS_CONTROL_ALLOW_ORIGIN, result) must equalTo(Some("*"))
header(ACCESS_CONTROL_ALLOW_HEADERS, result) must equalTo(Some(CONTENT_TYPE))
val expectedMethods = Seq(GET, PUT, POST, DELETE, "OPTIONS")
header(ACCESS_CONTROL_ALLOW_METHODS, result) must containAllOf(expectedMethods)
}
}
Run Code Online (Sandbox Code Playgroud)
如何在Specs2中表达"这个字符串是否包含所有这些值"的用例?
我正在尝试学习Clojure,并且在文字函数语法方面受阻.我无法弄清楚文字函数的等价物(defn fourteen [] 14)是什么.
(def fourteen (fn [] 14))
;; => #'user/fourteen
(fourteen)
;; => 14
(defn defn-fourteen [] 14)
;; => #'user/defn-fourteen
(defn-fourteen)
;; => 14
(def literal-14 #(14))
;; => #'user/literal-14
(literal-14)
;; ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn user/literal-14 (form-init2956929406616221071.clj:1)
Run Code Online (Sandbox Code Playgroud)
我不认为这是一个重复的匿名函数在clojure中期望多少个参数?,但也许它是,我只是没有经验来认识到这一点.
我如何或者可以使用def literal-14来允许(literal-14)调用工作?
我想知道Clojure是否有比如何验证Java中的 String是否是用于检测给定String是否是有效URL的有效URL 所描述的更好的工具.
是否有人包装Apache Commons Validator?有没有我不知道的独立图书馆?
我没有得到关于Java互操作的东西.我有一个字符java.lang.String"x".Java字符串有一个getBytes方法,其签名是public byte[] getBytes(String charsetName) throws UnsupportedEncodingException:https:
//docs.oracle.com/javase/7/docs/api/java/lang/String.html#getBytes(java.lang.String .
该方法返回一个byte [].Java数组有一个属性.length.为什么我在REPL中得到IllegalArgumentException?
(.length (.getBytes "x" "UTF-8"))
IllegalArgumentException No matching field found: length for class [B clojure.lang.Reflector.getInstanceField (Reflector.java:271)
Run Code Online (Sandbox Code Playgroud)
如何正确获取(.getBytes "x" "UTF-8")clojure 返回的字节数组的长度?
我是SBT的新手,不确定执行该evicted任务中的一个相当可怕的警告该怎么做: [warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
完整的任务输出为...
sbt:Sprout> evicted
[info] Updating ...
[info] Done updating.
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
[warn] Found version conflict(s) in library dependencies; some are suspected to be binary incompatible:
[warn] * org.scala-lang.modules:scala-xml_2.12:1.1.0 is selected over 1.0.6
[warn] +- org.json4s:json4s-xml_2.12:3.6.3 (depends on 1.1.0)
[warn] +- org.scalatra:scalatra_2.12:2.6.5 (depends on 1.0.6)
[warn] +- com.typesafe.play:twirl-api_2.12:1.3.13 …Run Code Online (Sandbox Code Playgroud) 我是Scala的新手,正在努力应对这种最愚蠢的事情.
我有一个List [String],我想解析列表并生成一个新的List [ServerAddress](ServerAddress是一个mongo的东西.我在概念上试图做的是将一个Type的List转换为另一个Type).我该怎么做呢?我当前的尝试无法填充我的列表[ServerAddress]
scala> val seeds: List[String] = List( "bobk-mbp.local", "bobk-mbp.local:27018" )
seeds: List[String] = List(bobk-mbp.local, bobk-mbp.local:27018)
scala> val serverAddrs = List[ServerAddress]()
serverAddrs: List[com.mongodb.casbah.Imports.ServerAddress] = List()
scala> for (seed <- seeds ) { new ServerAddress(seed) :: serverAddrs }
scala> serverAddrs
res12: List[com.mongodb.casbah.Imports.ServerAddress] = List()
Run Code Online (Sandbox Code Playgroud)
兄弟,你能不知道吗?