在我的Mac上,命令终端中指示的Java版本是1.7.0_40.Java控制面板(系统偏好设置)表示1.7.0_51.
他们为什么不同?
一些其他信息:
从命令终端/usr/libexec/java_home -V响应:
Matching Java Virtual Machines (3):
1.7.0_40, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
1.6.0_65-b14-462, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
1.6.0_65-b14-462, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Run Code Online (Sandbox Code Playgroud)
JAVA_HOME 被设置为:
/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
Run Code Online (Sandbox Code Playgroud)
从命令终端java -version响应:
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
Run Code Online (Sandbox Code Playgroud) 考虑以下向量:
std::vector<std::shared_ptr<X>> myVector;
Run Code Online (Sandbox Code Playgroud)
以及以下两个将给定元素添加到向量的函数:
void foo1(std::shared_ptr<X> x)
{
myVector.push_back(x);
}
void foo2(const std::shared_ptr<X>& x)
{
myVector.push_back(x);
}
Run Code Online (Sandbox Code Playgroud)
我的理解是,这两个函数都将 a 推shared_ptr入X向量中,从而增加 的引用计数X。第一个函数导致引用计数的额外递增和递减,但这是不必要的。
我的理解正确吗?那么第二种选择是否更可取呢?
c++ reference-counting pass-by-value shared-ptr pass-by-const-reference
我很困惑在使用Maven时通过命令行为某些单元测试设置属性的正确方法.有一些问题(如指定Maven的内存参数没有设置MAVEN_OPTS环境变量,有没有办法通过命令行传递JVM参数传递给Maven的?,如何设置JVM参数JUnit测试?)在这个问题上的那一抹但没有人能找到我想要的答案.
我想将属性设置java.util.logging.config.class为某个值,但我不想设置MAVEN_OPTS环境变量.
我可以使用属性在我的pom文件中配置surefire插件:
<argLine>-Djava.util.logging.config.class=someClass</argLine>
Run Code Online (Sandbox Code Playgroud)
这样每次运行测试阶段时都会设置它.
但是,如果我从pom文件中删除该设置并将以下内容添加到命令行:
mvn package -DargLine="java.util.logging.config.class=someClass"
Run Code Online (Sandbox Code Playgroud)
然后报告测试阶段中的以下错误,并且构建失败:
错误:无法找到或加载主类java.util.logging.config.class = someClass
如果我从命令行运行以下命令:
mvn package -Djava.util.logging.config.class=someClass
Run Code Online (Sandbox Code Playgroud)
然后在构建开始时报告以下错误,但构建和测试成功:
记录配置类"someClass"失败java.lang.ClassNotFoundException:someClass
我真的不明白这种行为.有人可以开导我吗?
以下代码使用XCode 5.0但不是Visual Studio 2013编译正常.
#include <vector>
class VectorInit
{
private:
std::vector<int> m_vector{1, 2, 3}; // fails to compile using VS 2013
};
int main()
{
std::vector<int> vector{1, 2, 3};
VectorInit vectorInit;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是Visual Studio报告的错误:
Error 1 error C2664: 'std::vector<int,std::allocator<_Ty>>::vector(std::initializer_list<int>,const std::allocator<_Ty> &)' : cannot convert argument 3 from 'int' to 'const std::allocator<_Ty> &' c:\visual studio 2013\projects\vector-init\main.cpp 6 1 vector-init
Run Code Online (Sandbox Code Playgroud)
我还没有设法找到一个如何在类定义中初始化这样的向量的示例.
哪个编译器正确?
如果语法无效,是在构造函数初始化列表中初始化m_vector的唯一选项吗?
我刚开始使用Apache PDFBox并且正在尝试我发现的各种示例.
但是,在添加文本时,我无法找到一种简单的方法来移动到下一行.
例如
PDPageContentStream content = new PDPageContentStream(document, page);
PDFont font = PDType1Font.HELVETICA;
content.beginText();
content.setFont(font, 12);
content.moveTextPositionByAmount(x, y);
content.drawString("Some text.");
content.endText();
Run Code Online (Sandbox Code Playgroud)
要在下面添加另一行文本,我必须反复尝试y in的值,moveTextPositionByAmount直到它没有覆盖前一行.
是否有更直观的方法来确定下一行的坐标是什么?
TIA
我想检查给定的字符串是否是使用boost的有效UUID.
这是我通过查看boost网站上的文档得出的:
void validate_uuid(const std::string& value)
{
try
{
boost::uuids::string_generator stringGenerator;
(void)stringGenerator(value);
}
catch (const std::exception& ex)
{
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这并不总是有效.
如果我使用对于有效UUID而言太短的字符串调用该函数,则会按预期抛出异常.但是如果我用无效的UUID调用该函数(例如00000000-0000-0000-0000-00000000000K),则不会抛出任何异常.
有人可以澄清为什么会这样.
另外,我已经看到使用boost :: lexical_cast将字符串读取为此处发布的UUID .我想知道我是否应该采用这种方法.任何建议表示赞赏
我正在使用 Jackson 反序列化一些 JSON,并且在尝试对其中一个字段使用自定义反序列化器时遇到了一些麻烦。
class MyClass
{
private static class SpecialPropertyDeserializer extends JsonDeserializer<SpecialProperty>
{
@Override
public SpecialProperty deserialize(JsonParser jsonParser,
DeserializationContext deserializationContext) throws IOException, JsonProcessingException
{
// do some custom deserialisation
}
}
private static class SpecialProperty
{
private String m_foo;
private String m_bar;
@JsonCreator
SpecialProperty(@JsonProperty("foo") String foo,
@JsonProperty("bar") String bar)
{
m_foo = foo;
m_bar = bar;
}
}
private String m_identifier;
private String m_version;
@JsonDeserialize(using = SpecialPropertyDeseializer.class)
private SpecialProperty m_specialProperty;
@JsonCreator
MyClass(@JsonProperty("identifier") String identifier,
@JsonProperty("version") String version,
@JsonProperty("specialProperty") SpecialProperty …Run Code Online (Sandbox Code Playgroud) 我正在使用 VS 2017 在调试模式下构建我的应用程序。我已经在发布模式下构建了它依赖并链接到的第 3 方库。这是允许的还是报告错误的原因。
LNK2038 mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MTd_StaticDebug' in xxx.obj my-application <path-to>\libboost_filesystem-mt-s.lib(path_traits.obj) 1
Run Code Online (Sandbox Code Playgroud)
该页面指出:
RuntimeLibrary 指示应用程序或库使用的 C++ 标准库和 C 运行时的版本。使用一个版本的 C++ 标准库或 C 运行时的代码与使用不同版本的代码不兼容。有关详细信息,请参阅 /MD、/MT、/LD(使用运行时库)。
我知道 DLL 运行时库不能与非 DLL 库混合使用。调试和发布库也是如此吗?
我在 Linux 上做同样的事情没有任何问题。
我使用 Keycloak 4.4.0 来保护我的 REST 服务,该服务是使用 Spring Boot 实现的,我使用 React 作为前端。
当前端(在 上运行localhost:3000)进行 API 调用localhost:8080/login并被重定向到 Keycloak 登录页面时,我收到 CORS 错误。
错误是:
localhost/:1 加载http://localhost:8080/login失败:从“ http://localhost:8080/login ”重定向到“ http://localhost:9080/auth/realms/hbs/protocol/openid- connect/auth?response_type=code&client_id=hbs&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Flogin&state=ab5034a9-4baa-4be3-9ec1-feefbe5f9c0b&login=true&scope=openid '已被禁止控制 - 'Allow Access- openid ' 策略已被 CORS 阻止-Origin' 标头存在于请求的资源上。因此,不允许访问Origin ' http://localhost:3000 '。
我在 Keycloak 客户端'*'的Web Origins配置部分添加了一个值。
我已将我的 REST 控制器注释如下:
@RestController
class MyController
{
@CrossOrigin
@GetMapping("/login")
public ResponseEntity<Foo> getFoo(Principal principal)
{
return ResponseEntity.ok(new Foo("blah"));
}
}
Run Code Online (Sandbox Code Playgroud)
我在应用程序属性中启用了 Keycloak 和 CORS: …
当我尝试在 IntelliJ 中运行简单的 JUnit 5 测试时,报告以下错误:
Feb 08, 2019 3:37:39 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNING: TestEngine with ID 'junit-vintage' failed to discover tests
java.lang.NoSuchMethodError: org.junit.platform.engine.EngineDiscoveryRequest.getDiscoveryFiltersByType(Ljava/lang/Class;)Ljava/util/List;
at org.junit.vintage.engine.discovery.JUnit4DiscoveryRequestResolver.filterAndConvertToTestClassRequests(JUnit4DiscoveryRequestResolver.java:79)
at org.junit.vintage.engine.discovery.JUnit4DiscoveryRequestResolver.resolve(JUnit4DiscoveryRequestResolver.java:48)
at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:64)
at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:177)
at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:164)
at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:120)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute(Lorg/junit/platform/launcher/LauncherDiscoveryRequest;)V
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:61)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
这是我的 pom:
<properties>
<java.version>1.8</java.version>
<junit.jupiter.version>5.3.2</junit.jupiter.version>
</properties>
</dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId> …Run Code Online (Sandbox Code Playgroud)