在Docker容器中播放2.5.x而不是通过共享文件夹更新

时间:2016-10-01 15:15:17

标签: scala intellij-idea docker playframework-2.0 sbt

我正在Docker容器中运行Play Framework 2.5.x的开发环境。该应用程序工作,我可以通过共享端口在我的浏览器上查看它。但是,自动更新功能不起作用。

从研究中我了解到这是因为Play的JNotify不会轮询共享文件夹中的文件更改。我已经尝试过这个问题的解决方案,只需在时间间隔内通过将以下内容添加到package stackoverflow.test; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Test { public List<Integer> list = new ArrayList<Integer>(); public List<Integer> dup = new ArrayList<Integer>(); public Map<Integer, Integer> hashDup = new HashMap<Integer, Integer>(); public void fileReader() { File file = new File("/home/john/Documents/file1.txt"); List<Integer> list1 = this.output(file); File file2 = new File("/home/john/Documents/file2.txt"); List<Integer> list2 = this.output(file2); for (int i = 0; i < list1.size(); i++) { int counter = 0; for (int j = 0; j < list2.size(); j++) { if (list1.get(i) == list2.get(j)) { counter++; } } if (!hashDup.containsKey(list1.get(i))) { hashDup.put(list1.get(i), counter); System.out.println(" dup " + list1.get(i) + " :" + counter); } } } public List<Integer> output(File file) { BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); String text = null; while ((text = reader.readLine()) != null) { // System.out.println( text); String[] str = text.split(" "); for (String string : str) { list.add(Integer.parseInt(string)); } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { } } // print out the list // System.out.println(list.toString()); return list; } public static void main(String args[]) { Test t = new Test(); t.fileReader(); } }

进行轮询

build.sbt

进行此更改(并确保将其推送到共享文件夹)后,使用PlayKeys.fileWatchService := play.runsupport.FileWatchService.sbt(pollInterval.value)成功编译并运行服务器。

activator run

我可以在浏览器中查看。但是,在更改文件时,不会进行重新编译,刷新也不会更改任何内容。但是,停止和启动服务器会显示更改。

我想我可能知道为什么,但我不知道如何解决它。我已经读过,假设使用[info] Done updating. --- (Running the application, auto-reloading is enabled) --- [info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000 (Server started, use Ctrl+D to stop and go back to the console...) 启动服务器,但使用SBT而不是激活器。当我使用此命令启动服务器时,它挂起:

activator ~run

0 个答案:

没有答案