小编Nic*_*s K的帖子

DockerFile运行java程序

嗨,我是Docker的新手,并尝试从头开始编写新图像.我正在编写这个dockerFile来编译和运行同一目录中可用的简单java程序.

这是dockerfile.

FROM scratch
CMD javac HelloWorld.java
CMD java HelloWorld
Run Code Online (Sandbox Code Playgroud)

Docker构建成功,如下所示

[root@hadoop01 myjavadir]# docker build -t runhelloworld .
Sending build context to Docker daemon 3.072 kB
Sending build context to Docker daemon
Step 0 : FROM scratch
 --->
Step 1 : CMD javac HelloWorld.java
 ---> Running in 7298ad7e902f
 ---> f5278ae25f0c
Removing intermediate container 7298ad7e902f
Step 2 : CMD java HelloWorld
 ---> Running in 0fa2151dc7b0
 ---> 25453e89b3f0
Removing intermediate container 0fa2151dc7b0
Successfully built 25453e89b3f0
Run Code Online (Sandbox Code Playgroud)

但是当我尝试运行时,它会抛出以下错误:

[root@hadoop01 myjavadir]# docker run runhelloworld
exec: …
Run Code Online (Sandbox Code Playgroud)

java docker

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

模块在角度模块中没有导出成员错误

我想创建一个功能模块来处理上传的前端。

upload.component.html 没有错误。

<input
  type="file"
  #file
  style="display: none"
  (change)="onFilesAdded()"
  multiple
/>

<button mat-raised-button (click)="openUploadDialog()">Upload</button>
Run Code Online (Sandbox Code Playgroud)

upload.component.ts 2 错误 - 导入上传和对话框组件

import { Component } from '@angular/core'
import { MatDialog } from '@angular/material'
import { DialogComponent } from './dialog/dialog.component'
import { UploadService } from './upload.service'

@Component({
  selector: 'app-upload',
  templateUrl: './upload.component.html',
  styleUrls: ['./upload.component.css'],
})
class UploadComponent {
  constructor(public dialog: MatDialog, public uploadService: UploadService) {}

  public openUploadDialog() {
    let dialogRef = this.dialog.open(DialogComponent, {
      width: '50%',
      height: '50%',
    })
  }
}
Run Code Online (Sandbox Code Playgroud)

upload.module.ts 3个错误,导入DialogComponent、上传服务、上传组件

import { …
Run Code Online (Sandbox Code Playgroud)

typescript angular-module angular

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

反应原生选择器没有在android中显示

我正在尝试添加picker in react native android但它没有在android中显示.我将我的位置日期映射到选择器项目,但我没有在屏幕上看到选择器.

<Picker selectedValue={this.state.location}>
  <Picker.Item label="Location 1" value="1" /> 
  <Picker.Item label="Location 2" value="2" />
  <Picker.Item label="Location 3" value="3" />
</Picker>
Run Code Online (Sandbox Code Playgroud)

android react-native

10
推荐指数
4
解决办法
9945
查看次数

python中的方法重载

我需要调用unparameterised方法first,但也参数化first,但它给出了一个错误.

>>> class A:
...     def first(self):
...             print 'first method'
...     def first(self,f):
...             print 'first met',f
...
>>> a=A()
>>> a.first()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: first() takes exactly 2 arguments (1 given) 
Run Code Online (Sandbox Code Playgroud)

是否可以像在Java中一样在Python中执行方法重载?

python overloading

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

如何在java中仅使用lambda按升序和降序对整数数组进行排序

int[] arr2 = new int[] {54, 432, 53, 21, 43};
Run Code Online (Sandbox Code Playgroud)

我正在使用它来排序,但它给出了一个错误.

Arrays.sort(arr2, (a, b) -> a - b);
Run Code Online (Sandbox Code Playgroud)

这也是一个错误.

arr2.sort((a, b) -> a - b);
Run Code Online (Sandbox Code Playgroud)

java arrays lambda java-8 java-stream

9
推荐指数
3
解决办法
4417
查看次数

如何初始化@Input?

我尝试这样做:

  @Input() data: any[] = [];
Run Code Online (Sandbox Code Playgroud)

在 ngOnInit 里面我看到undefined

 ngOnInit() {
    console.log(this.data);
  }
Run Code Online (Sandbox Code Playgroud)

因此,当我尝试获取长度时,在下面的代码中出现错误:return this.data.length;

因为它是未定义的。

为什么默认情况下初始化不起作用?

@Input() data: any[] = [];
Run Code Online (Sandbox Code Playgroud)

typescript angular angular-lifecycle-hooks

9
推荐指数
1
解决办法
8442
查看次数

JavaScript中的原型链接

我正在读一本名为JavaScript模式的书,但有一部分我觉得这个人很困惑.

这个家伙实际上在书中引出了klass设计模式,在那里他逐一开发了它.他首先提出了这个问题:

function inherit(C, P) {
C.prototype = P.prototype;
}
Run Code Online (Sandbox Code Playgroud)

他说:

"这为您提供了简短快速的原型链查找,因为所有对象实际上共享相同的原型.但这也是一个回顾,因为如果继承链中的某个子项或孙子修改原型,它会影响所有父母和祖父母."

但是,我实际上试图在Child中修改原型say()并且它对Parent没有影响,实际上Child仍指向Parent并且完全忽略了它自己的同名原型,这是有意义的,因为它指向不同的内存位置.那家伙怎么能这样说呢?以下证明了我的观点:

function Parent(){}

Parent.prototype.say = function () {
return 20;
};

function Child(){
}

Child.prototype.say = function () {
return 10;
};

inherit(Child, Parent);

function inherit(C, P) {
C.prototype = P.prototype;
 } 

 var parent = new Parent();
var child = new Child();


var child2 = new Child()
alert(child.say(); //20
alert(parent.say()); //20
alert(child2.say()); //20
Run Code Online (Sandbox Code Playgroud)

任何孩子或孙子都不可能修改原型!

这导致了我的第二点.他说,在继承链(我无法重现)中意外修改父原型的可能性问题的解决方案是打破父母和孩子原型之间的直接联系,同时从原型链中受益.他提供以下解决方案:

function inherit(C, P) {
var F = function () {};
F.prototype = P.prototype; …
Run Code Online (Sandbox Code Playgroud)

javascript inheritance prototype reference chaining

8
推荐指数
1
解决办法
2203
查看次数

如何在角度2+中将md ElementRef强制转换为HtmlElement

我有

 <input mdInput #try  placeholder="Favorite food" value="Sushi">
Run Code Online (Sandbox Code Playgroud)

而且我得到了它

 @ViewChild('try') myText : ElementRef;
Run Code Online (Sandbox Code Playgroud)

现在我需要得到HtmlElement函数的方法,我怎么能投出它?

并且我不希望通过这种方式添加id="try"到mdInput并通过以下方式 获取:

var cel= document.getElementById("try");
Run Code Online (Sandbox Code Playgroud)

casting typescript angular

8
推荐指数
1
解决办法
7547
查看次数

Wiremock存根-WithBodyFile位置_files以外的位置

Wiremock文档指出,在withBodyFile中指定的文件位置应该在src / test / resources / __ files中。我想在src / test / resources / Testing_ABC / Testcase2 / myfile.xml中拥有文件

有什么办法可以实现?我尝试了以下操作,但似乎不起作用!

stubFor(get(urlPathEqualTo("/abc")).willReturn
                (aResponse().withHeader("Content-Type",
                        "text/xml; charset=utf-8").withHeader
                        ("Content-Encoding",
                                "gzip")
                        .withBodyFile
                                ("src/test/resources/Testing_ABC/Testcase2/myfile.xml)));
Run Code Online (Sandbox Code Playgroud)

但是,当我将文件放入src / test / resources / __ files / myfile.xml并相应地更改路径时,它可以正常工作。

我只是想知道是否可以使Wiremock在__files以外的资源的其他目录中查找,以便在项目中具有良好的资源结构。

java stubbing wiremock

8
推荐指数
1
解决办法
3661
查看次数

(谓词<?super String> s)或(String s)

我有一个TreeSet字符串(硬编码).想要检查给定的参数String例如."Person"如果存在于TreeSet中则返回true否则返回false.

在这里我对关于(Predicate<? super String> s)vs 的Eclipse消息感到困惑 (String s):

类型Stream中的方法anyMatch(Predicate)不适用于参数(String)

请指导.

import java.util.Set;
import java.util.TreeSet;
import java.util.function.Predicate;

public class SystemLabelValidator {

    public static boolean ValidateSystemLabel( String s) {  

        String j = s;

        boolean b = false;

        Set <String> SystemLabels = new TreeSet<String>();
        // Unique Strings
        SystemLabels.add("Person");
        SystemLabels.add("Player");
        SystemLabels.add("Hospital");
        SystemLabels.add("Nurse");
        SystemLabels.add("Room");

        System.out.println("\n==> Loop here.");
        for (String temp : SystemLabels) {
            System.out.println(temp);

            if(SystemLabels.stream().anyMatch(j)) {
                System.out.println("I need to return Boolean");
            }
            return b;
        }
        return …
Run Code Online (Sandbox Code Playgroud)

java string predicate java-8 java-stream

8
推荐指数
1
解决办法
272
查看次数