我点击了这个eclipse错误,那里System.console()没有Java应用程序启动.我有一个小型Java应用程序,它还需要输入一个只能在IDE中启动的密码.有没有其他方法可以从控制台安全地读取密码(意味着不在控制台上显示)只使用JDK类?
编辑:
我知道System.in,但这是在控制台中显示输入的字符,因此不安全.
编辑2:
我还想注意,可以在windows下创建一个批处理文件,或者在项目中的linux/unix下创建一个小的bash脚本.通过使用系统默认编辑器在eclipse中打开此文件,它将在可用的新控制台窗口中启动System.console().这样你就可以在eclipse中启动应用程序.但是必须首先构建项目,以便存在二进制文件.
我常常发现使用pre-java-8设置实现构建器模式很繁琐.总是有很多几乎重复的代码.构建器本身可以被视为样板.
事实上,有代码重复检测器,几乎可以考虑使用pre-java-8工具制作的构建器的每个方法作为每个其他方法的副本.
所以考虑下面的类和它的pre-java-8构建器:
public class Person {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
public class PersonBuilder {
private static class PersonState {
public String name;
public int age;
}
private PersonState state = new PersonState();
public PersonBuilder withName(String name) {
state.name = name;
return this; …Run Code Online (Sandbox Code Playgroud) 给出以下课程:
public class FooTest {
public static class Base {
}
public static class Derived extends Base {
}
public interface Service<T extends Base> {
void service(T value);
}
public abstract class AbstractService<T extends Derived> implements Service<T> {
public void service(T value) {
}
}
private AbstractService service;
public void bar(Base base) {
if(base instanceof Derived) {
service.service(base); // compile error at this line
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用以下内容构建类时pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mgm-tp</groupId>
<artifactId>java-compiler-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build> …Run Code Online (Sandbox Code Playgroud) 我用eclipse-plugin包装创建了一个Tycho项目.该项目包含一些通过pom.xml指定的依赖项.相关的pom部分是:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tycho.version>0.15.0</tycho.version>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho.version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho.version}</version>
<configuration>
<pomDependencies>consider</pomDependencies>
<environments>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>juno</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/juno</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.release</id>
<name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/release</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/external</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>com.springsource.org.testng</artifactId>
<version>6.4.0</version>
</dependency> …Run Code Online (Sandbox Code Playgroud) 假设如下:
@SomeAnnotation
public interface Foo {
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否始终如此定义的类加载器SomeAnnotation等于或者是启动类加载器的父类Foo.
我已阅读JVMS v8第5.3节.但我不确定这里适用的是什么.第5.3.4节讨论了加载约束,但它们似乎不适用于注释.
我问的问题是因为这样的代码:
Class<?> fooClass = //will in some way obtain a reference to class Foo
fooClass.getAnnotation(SomeAnnotation.class);
Run Code Online (Sandbox Code Playgroud)
在不同的类加载器存在的情况下会失败.我知道我可以使用getAnnotations并在结果数组中搜索类名等于的名称的元素SomeAnnotation.但我想知道以下是否也会有效:
Class<?> fooClass = //will in some way obtain a reference to class Foo
fooClass.getAnnotation((Class<? extends Annotation>) fooClass
.getClassLoader().loadClass(SomeAnnotation.class.getName()));
Run Code Online (Sandbox Code Playgroud) 我想回顾一下同事的补丁.我们无法使用审核工具.所以我想评论他制作的补丁文件.是否可以在(svn)补丁文件中写入内联注释?
我在svn红皮书中找不到任何信息.我甚至无法找到补丁文件语法来弄清楚自己.
我java.lang.Class.newInstance0()在JDK 1.7 Update 7中看到了以下注释:
注意:在当前Java内存模型下,以下代码可能不严格正确.
任何人都可以解释一下原因吗?
我如何快速转发分支机构,当我git fetch上网期间编辑时,现在我处于离线状态,并希望快速前进到我之前提取的状态.
例如,我离线并执行以下操作:
$ git checkout develop
Switched to branch 'develop'
Your branch is behind 'origin/develop' by 37 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Run Code Online (Sandbox Code Playgroud)
在尝试使用时,git pull我得到:
$ git pull
ssh: Could not resolve hostname <hostname>: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
在这种情况下我需要使用什么命令?
我想创建一个solr的docker镜像,在启动时创建一个核心.因此,我正在使用为solr docker容器描述的docker-entrypoint-initdb.d扩展机制.文件说
在启动时创建核心的第三种方法是使用下一节中介绍的图像扩展机制.
但它并没有解释如何实现这一目标.
我正在使用的Dockerfile是:
FROM solr:6.6
USER root
RUN mkdir /A12Core && chown -R solr:solr /A12Core
COPY --chown=solr:solr ./services-core/search/A12Core /A12Core/
COPY --chown=solr:solr ./create-a12core.sh /docker-entrypoint-initdb.d/
USER solr
RUN chmod -R a+X /A12Core
Run Code Online (Sandbox Code Playgroud)
该文件夹A12Core包含核心的solr配置文件.create-a12core.sh创建核心的脚本是:
#!/bin/bash
solr-precreate A12Core /A12Core
Run Code Online (Sandbox Code Playgroud)
该/A12Core目录包含以下文件:
./core.properties
./conf
./conf/update-script.js
./conf/mapping-ISOLatin1Accent.txt
./conf/schema.xml
./conf/spellings.txt
./conf/solrconfig.xml
./conf/currency.xml
./conf/mapping-FoldToASCII.txt
./conf/_schema_analysis_stopwords_english.json
./conf/stopwords.txt
./conf/synonyms.txt
./conf/elevate.xml
./conf/lang
./conf/lang/stopwords_en.txt
./conf/lang/stopwords_de.txt
Run Code Online (Sandbox Code Playgroud)
但是,当使用上面的Dockerfile和脚本启动图像构建时,似乎会创建一个无限循环.输出是:
/opt/docker-solr/scripts/solr-foreground: running /docker-entrypoint-initdb.d/create-a12core.sh
Executing /opt/docker-solr/scripts/solr-precreate A12Core /A12Core
/opt/docker-solr/scripts/solr-precreate: running /docker-entrypoint-initdb.d/create-a12core.sh
Executing /opt/docker-solr/scripts/solr-precreate A12Core /A12Core
/opt/docker-solr/scripts/solr-precreate: running …Run Code Online (Sandbox Code Playgroud) 我有一个要求,即一个名字不能以3个相同的字母开头而忽略它们的情况.名称以大写字母开头,后跟小写字母.
基本上我可以将整个名称转换为大写,然后匹配正则表达式(\p{Lu})\1{3,}.*.
但我想知道是否存在符合上述要求的正则表达式,并且不需要对要匹配的字符串进行任何预处理.那么我可以使用什么正则表达式匹配字符串Aa,Dd或者Uu没有明确指定任何可能的组合?
编辑:
我接受了Markos的回答.我只需要修复它以使用长度为1和2的名称并将其锚定在开头.所以我的用例的实际正则表达式是^(\p{Lu})(\p{Ll}?$|(?=\p{Ll}{2})(?i)(?!(\1){2})).
我也赞成了Evgeniy和sp00m的答案,帮助我学习正则表达式的一课.
谢谢你的努力.