小编Jul*_*les的帖子

Java ClassLoader getResource,路径中包含特殊字符

我有以下问题.在我们的集成测试中,我们使用不同的配置,它将在测试之前使用以下代码从测试资源加载:

URL resource = ClassLoader.getSystemResource("application.conf");
Run Code Online (Sandbox Code Playgroud)

只要路径中没有特殊字符,这就可以正常工作.例如,具有以下正确路径

D:/Dev/projects/#FLI/flinsta/fgraph/build/resources/test/application.conf
Run Code Online (Sandbox Code Playgroud)

将导致以下错误的文件路径getSystemResource:

D:/Dev/projects/%23FLI/flinsta/fgraph/build/resources/test/application.conf
Run Code Online (Sandbox Code Playgroud)

然后,这将导致一个根本不存在的文件.我怎样才能确保不会发生这样的事情.重命名路径是一种选择.但是,我想找到一个解决方案而不是解决方法.

感谢您的任何帮助!

java

7
推荐指数
1
解决办法
3499
查看次数

Java - groupingBy with collectingAndThen - 是否有更快/更好/更清洁的方式?

我有以下课程(有getter):

public class AlgorithmPrediction {
    private final String algorithmName;
    private final Map<BaseDatabaseProduct, Double> productsToAccuracy;
}
Run Code Online (Sandbox Code Playgroud)

现在我想从一个由AlgorithmPrediction对象填充的集合中创建一个映射,其中algorithmName (唯一)作为键和productsToAccuracy值.我想不出比这更复杂的东西:

algorithmPredictions.stream()
.collect(
        groupingBy(
                AlgorithmPrediction::getAlgorithmName,
                Collectors.collectingAndThen(
                        toSet(),
                        s -> s.stream().map(AlgorithmPrediction::getProductsToAccuracy).collect(toSet())
                )
        )
);
Run Code Online (Sandbox Code Playgroud)

这不可能是对的.我错过了什么?谢谢!

java lambda grouping java-8 collectors

6
推荐指数
2
解决办法
3880
查看次数

CoreOS - 如何使用新令牌?

我们有以下问题.在我们的群集中,网址已经改变了.一旦我们更改配置以反映这些更改,网址就不会在'discovery.etcd.io'上更新.所以我们的想法就是使用一个新的令牌.然而,这不起作用.群集未在"discovery.etcd.io"上注册新令牌.每次我们更改网址或令牌时,我们都不想重新安装.有没有更好的办法?重新安装工作没有问题.

#cloud-config
hostname: server1
coreos:
  etcd2:
    # generate a new token for each unique cluster from https://discovery.etcd.io/new?size=3
    discovery: https://discovery.etcd.io/<our token>
    # multi-region and multi-cloud deployments need to use $public_ipv4
    advertise-client-urls: server1:2379
    initial-advertise-peer-urls: server1:2380
    # listen on the official ports
    listen-client-urls: server1:2379
    listen-peer-urls: server1:2380
  #fleet:
  #    public-ip: server1
  #    metadata: region=eu-central-1
  #update:
  #  reboot-strategy: etcd-lock
  units:
    - name: etcd2.service
      command: start
   # - name: fleet.service
   #   command: start
ssh_authorized_keys:
   <our ssh keys>
Run Code Online (Sandbox Code Playgroud)

coreos

5
推荐指数
1
解决办法
829
查看次数

数据库自动创建 -&gt; 找不到参数会话的隐式值

我是 Scala 的新手(长期 Java 开发人员)。我试图理解隐式,我想我理解了基础知识,但是我不明白为什么它找不到隐式值session。我试图用尽可能多的信息来描述我的问题。

我关注了以下博客文章:http : //blog.websudos.com/2015/04/04/a-series-on-phantom-part-1-getting-started-with-phantom/

一切顺利/编译正常,直到我想测试它。得到以下错误:

Error:(15, 46) could not find implicit value for parameter session: com.datastax.driver.core.Session
    Await.result(Database.autocreate().future(), 5.seconds)
                                             ^
Error:(20, 48) could not find implicit value for parameter session: com.datastax.driver.core.Session
    Await.result(Database.autotruncate().future(), 5.seconds)
                                               ^
Run Code Online (Sandbox Code Playgroud)

当我执行以下测试类时:

import org.joda.time.DateTime
import org.scalatest.{BeforeAndAfterAll, FlatSpec}

import scala.concurrent.Await
import scala.concurrent.duration._

class DatabaseTest extends FlatSpec with BeforeAndAfterAll{
  override def beforeAll(): Unit = {
    super.beforeAll()
    Await.result(Database.autocreate().future(), 5.seconds)
  }

  override def afterAll(): Unit = {
    super.afterAll()
    Await.result(Database.autotruncate().future(), 5.seconds)
  }

  "A TwitterMessage" should "be …
Run Code Online (Sandbox Code Playgroud)

scala phantom-dsl

3
推荐指数
1
解决办法
930
查看次数

SBT 远程调试在 intellij 中有效,但在执行测试时无效

我在终端中执行以下命令sbt -jvm-debug 9999并使用 Intellij 15.0.4-1 中的默认值启动远程调试配置。接下来我执行 sbt 任务run,断点按预期工作。当我执行test任务时,尽管执行了相同的代码,但调试将不再起作用。

play-scala激活剂种子与Play Framework 2.4. 测试是在规范 2 中编写的。有谁知道我可能做错了什么?

这是我的代码:

类 DebugTest.scala

object DebugTest {
  def helloWorld(): Unit ={
    println("Oh my")
  }
}
Run Code Online (Sandbox Code Playgroud)

类 ApplicationSpec.scala

import org.specs2.mutable._

import play.api.test._
import play.api.test.Helpers._

class ApplicationSpec extends Specification {

  "Application" should {
    "just print oh my in console" in new WithApplication{
      DebugTest.helloWorld()
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

文件 build.sbt

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.7"

libraryDependencies …
Run Code Online (Sandbox Code Playgroud)

debugging scala intellij-idea sbt playframework

3
推荐指数
1
解决办法
851
查看次数

Scala JS:在元素上调用Javascript函数

我有以下问题.我想在我的项目中使用https://github.com/aehlke/tag-it/.但是我不确定我应该如何实现github页面上给出的以下示例:

<script type="text/javascript">
$(document).ready(function() {
 $("#myTags").tagit();
});
</script>

<ul id="myTags">
 <!-- Existing list items will be pre-added to the tags -->
 <li>Tag1</li>
 <li>Tag2</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

到目前为止,我能够操纵对象:

val document = js.Dynamic.global.document
document.getElementById("myTags").innerHTML = "Test"
Run Code Online (Sandbox Code Playgroud)

这有效!Test正在呈现.

当我打电话给tagit()我时,我被告知tagit is not a function.

val document = js.Dynamic.global.document
document.getElementById("myTags").tagit()
Run Code Online (Sandbox Code Playgroud)

当我使用chrome java脚本控制台进行"相同"调用时,一切正常:

$("#myTags").tagit();
Run Code Online (Sandbox Code Playgroud)

谁能解释我做错了什么?先感谢您!

编辑

这不是tag-it或jquery没有被加载的问题.Chrome控制台再次起作用.这也不是装载问题.即使在所有内容加载100%后单击按钮也无效.

编辑

添加了我的部分构建定义,以便每个人都可以看到依赖项是正确的:

.jsSettings(
      jsDependencies ++= Seq(
        "org.webjars" % "bootswatch-yeti" % "3.3.5" / "js/bootstrap.js" minified "js/bootstrap.min.js" dependsOn "jquery.js",
        "org.webjars" % "jquery-ui" % "1.11.4" / …
Run Code Online (Sandbox Code Playgroud)

javascript scala scala.js

2
推荐指数
1
解决办法
1350
查看次数