为了进行测试,我们有一个DNS服务器,该服务器将响应虚拟记录。以前,我们可以通过以下方式使java使用我们的DNS服务器(此处仅使用本地主机):
"-Dsun.net.spi.nameservice.nameservers=127.0.0.1",
"-Dsun.net.spi.nameservice.provider.1=dns,sun",
Run Code Online (Sandbox Code Playgroud)
这在jdk11下不再起作用。是否可以指定在jdk11下使用的DNS服务器?如果可以,怎么办?
编辑:我也尝试过:
-Djava.naming.provider.url=dns://127.0.0.1
Run Code Online (Sandbox Code Playgroud)
最近的 groovy 升级带来了 JUnit5,导致 Eclipse 想要在 JUnit5 下运行每个测试。我可以通过运行配置并告诉 Eclipse 使用 JUnit4 来解决这个问题,但这会变得乏味。
是否可以告诉 Eclipse 始终将 JUnit4 用于特定项目,包括新测试?
我有一个DeclaredType字段,我想获得该字段的完全限定类型(原始类型?)。例如,如果该字段是:
public static Optional<String> foo;
Run Code Online (Sandbox Code Playgroud)
我想得到java.util.Optional。
目前我可以通过以下方式获取包名称:
env.getElementUtils().getPackageOf(declaredType.asElement());
Run Code Online (Sandbox Code Playgroud)
然而,我回来了同样的问题我结束了一个我能得到的那种类型参数List的TypeMirror,我不知道怎么弄类型的限定名。
我注意到我可以打电话TypeMirror#toString()并且会返回(对于上述)类似的东西:
java.util.Optional<java.lang.String>
Run Code Online (Sandbox Code Playgroud)
我想我可以把前面的所有东西都剪掉,<但这感觉就像一个黑客。
作为参考,这是我获取该字段的方式:
private VariableElement getFieldWithName(DocletEnvironment environment, TypeElement classDoc, String fieldName) {
for(VariableElement e : ElementFilter.fieldsIn(environment.getElementUtils().getAllMembers(classDoc))) {
if(e.getSimpleName().toString().equals(fieldName)) {
return e;
}
}
return null;
}
TypeElement classElement = env.getElementUtils().getTypeElement(MyClass.class.getCanonicalName());
VariableElement fieldDoc = getFieldWithName(env, classElement, "foo");
DeclaredType declaredType = (DeclaredType) fieldDoc.asType();
Run Code Online (Sandbox Code Playgroud) 是否可以告诉eclipse添加以下命令行选项:
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
编译时.
我认为在运行测试时也可能需要它.
请注意,我尝试将这些添加到我的一个单元测试的VM选项中,但这不起作用.
升级到jetty 9.4之后,我注意到了一个ClassNotFoundException org.eclipse.jetty.server.session.HashSessionManager.我想我需要使用一个,FileSessionDataStore但我不知道这是怎么设置的SessionHandler.
我目前的配置是:
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
...
<Set name="sessionHandler">
<New class="org.eclipse.jetty.server.session.SessionHandler">
<Arg>
<New class="org.eclipse.jetty.server.session.HashSessionManager">
<Set name="storeDirectory">my/store/path</Set>
</New>
</Arg>
</New>
</Set>
</Configure>
Run Code Online (Sandbox Code Playgroud)
我没有看到我需要做什么,SessionHandler没有拿a SessionDataStore,但是SessionCache可以设置它,但它看起来像是在构造函数中SessionCache想要的实现SessionHandler,我不知道如何在XML中这样做.
我想散列一个具有两个私有成员的类,例如:
foo.h
class Foo {
private:
std::string a;
std::string b;
public:
Foo (std::string a, std::string b);
bool operator==(const Foo& other) const;
bool operator!=(const Foo& other) const;
std::size_t operator()(const Foo& ) const;
};
namespace std {
template <> struct hash<Foo> {
std::size_t operator()(const Foo& cp) const;
};
}
Run Code Online (Sandbox Code Playgroud)
文件
Foo::Foo (std::string _a, std::string _b) {
this->a = _a;
this->b = _b;
}
bool Foo::operator== (const Foo& other) const {
return this->a == other.a && this->b == other.b;
}
bool Foo::operator!= (const …Run Code Online (Sandbox Code Playgroud)