您可以在构建自定义图像时设置图像名称,如下所示:
docker build -t dude/man:v2 . # Will be named dude/man:v2
Run Code Online (Sandbox Code Playgroud)
有没有办法在Dockerfile中定义图像的名称,所以我不必在docker build命令中提及它?
假设我有一个我想要标记的图像0.10.24(在我的例子中,它是一个包含Node.js 0.10.24的图像).我使用Dockerfile构建该图像并执行docker build并使用-t参数提供标记.
我希望有一天我会有该图像的其他版本,所以我将重新运行该过程,只需使用另一个标记名称.
到现在为止还挺好.这很好,很好,一切都很好.
但是,这就是问题开始的地方,我还希望latest另外还有最新的图像标记广告.所以我想我需要给同一个图像赋予两个名字.
我该怎么做呢?我是否真的需要重新运行docker build完全相同的版本,但这次使用另一个标签,是否有更好的选择?
我知道一种方法是:
@Test
public void foo(){
try{
//execute code that you expect not to throw Exceptions.
}
catch(Exception e){
fail("Should not have thrown any exception");
}
}
Run Code Online (Sandbox Code Playgroud)
有没有更清洁的方法来做到这一点.(可能使用Junit的@Rule?)
我正在寻找创建pdf我的网站网页的可打印版本.像express.render()只渲染页面的东西pdf
有谁知道这样做的节点模块?
如果没有,您将如何实施?我已经看到一些方法谈论使用无头浏览器phantom.js,但不确定流量是什么.
实际上这是完全理论上的问题.但有趣的是,为什么java规范不允许在包中使用大写字母字母并导致类似这样的写:
com.mycompany.projname.core.remotefilesystemsynchronization.*
Run Code Online (Sandbox Code Playgroud)
代替
com.myCompanyName.projName.core.remoteFileSystemSynchronization.*
Run Code Online (Sandbox Code Playgroud) 我正在开发一个Java企业应用程序,目前正在使用Java EE安全性来限制特定用户对特定功能的访问.我配置了应用程序服务器和所有内容,现在我使用RolesAllowed-annotation来保护方法:
@Documented
@Retention (RUNTIME)
@Target({TYPE, METHOD})
public @interface RolesAllowed {
String[] value();
}
Run Code Online (Sandbox Code Playgroud)
当我使用这样的注释时,它工作正常:
@RolesAllowed("STUDENT")
public void update(User p) { ... }
Run Code Online (Sandbox Code Playgroud)
但这不是我想要的,因为我必须在这里使用String,重构变得困难,并且可能发生拼写错误.因此,我想使用Enum值作为此注释的参数,而不是使用String.Enum看起来像这样:
public enum RoleType {
STUDENT("STUDENT"),
TEACHER("TEACHER"),
DEANERY("DEANERY");
private final String label;
private RoleType(String label) {
this.label = label;
}
public String toString() {
return this.label;
}
}
Run Code Online (Sandbox Code Playgroud)
所以我尝试使用Enum作为这样的参数:
@RolesAllowed(RoleType.DEANERY.name())
public void update(User p) { ... }
Run Code Online (Sandbox Code Playgroud)
但是后来我得到了以下编译器错误,虽然Enum.name只返回一个String(它总是不变的,不是吗?).
注释属性RolesAllowed.value的值必须是常量表达式`
我尝试的下一件事是在我的枚举中添加一个额外的最终字符串:
public enum RoleType {
...
public static final String STUDENT_ROLE = STUDENT.toString();
...
}
Run Code Online (Sandbox Code Playgroud)
但这也不能作为参数,导致相同的编译器错误:
// The …Run Code Online (Sandbox Code Playgroud) 在Java中,不可能直接创建泛型类型的数组:
Test<String>[] t1 = new Test<String>[10]; // Compile-time error
Run Code Online (Sandbox Code Playgroud)
但是,我们可以使用原始类型执行此操作:
Test<String>[] t2 = new Test[10]; // Compile warning "unchecked"
Run Code Online (Sandbox Code Playgroud)
在Java 8中,也可以使用构造函数引用:
interface ArrayCreator<T> {
T create(int n);
}
ArrayCreator<Test<String>[]> ac = Test[]::new; // No warning
Test<String>[] t3 = ac.create(10);
Run Code Online (Sandbox Code Playgroud)
为什么编译器在最后一种情况下不显示警告?它仍然使用原始类型来创建数组,对吗?
当我使用render {rmarkdown}从我的Mac上的.Rmd文件生成pdf文件时,会显示一条错误消息
pandoc: pdflatex not found. pdflatex is needed for pdf output.
Error: pandoc document conversion failed
但是当我检查时
pdflatex -v
Run Code Online (Sandbox Code Playgroud)
我有
pdfTeX 3.1415926-2.4-1.40.13 (TeX Live 2012)
kpathsea version 6.1.0
Copyright 2012 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty. Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of …Run Code Online (Sandbox Code Playgroud) 我已经写了一段时间的java,今天我遇到了以下声明:
public static void main(String... args) {
}
Run Code Online (Sandbox Code Playgroud)
注意数组声明中的"点点点",而不是通常的括号[].显然它有效.事实上,我写了一个小测试,并验证它的工作原理.所以,我拉了java语法,看看这个参数声明的语法在哪里,但没有找到任何东西.
所以对那里的专家来说,这是如何工作的?它是语法的一部分吗?另外,虽然我可以像这样声明函数,但是我不能像这样在函数体内声明一个数组.
无论如何,你知道任何有这个记录的地方.这是好奇心,也许不值得投入任何时间,但我很难过.
跟我说,介绍有点啰嗦,但这是一个有趣的难题.
我有这个代码:
public class Testcase {
public static void main(String[] args){
EventQueue queue = new EventQueue();
queue.add(() -> System.out.println("case1"));
queue.add(() -> {
System.out.println("case2");
throw new IllegalArgumentException("case2-exception");});
queue.runNextTask();
queue.add(() -> System.out.println("case3-never-runs"));
}
private static class EventQueue {
private final Queue<Supplier<CompletionStage<Void>>> queue = new ConcurrentLinkedQueue<>();
public void add(Runnable task) {
queue.add(() -> CompletableFuture.runAsync(task));
}
public void add(Supplier<CompletionStage<Void>> task) {
queue.add(task);
}
public void runNextTask() {
Supplier<CompletionStage<Void>> task = queue.poll();
if (task == null)
return;
try {
task.get().
whenCompleteAsync((value, exception) -> runNextTask()).
exceptionally(exception …Run Code Online (Sandbox Code Playgroud) java ×6
docker ×2
java-8 ×2
tags ×2
annotations ×1
arrays ×1
declaration ×1
dockerfile ×1
enums ×1
express ×1
generics ×1
java-ee ×1
java-ee-6 ×1
junit ×1
junit4 ×1
lambda ×1
macos ×1
node.js ×1
package ×1
pandoc ×1
pdflatex ×1
r ×1
r-markdown ×1
unit-testing ×1