我需要在使用Gradle构建时向我的jar添加默认JVM选项.从我得到的文档中我必须设置:
applicationDefaultJvmArgs = ["-Djavafx.embed.singleThread=true"]
Run Code Online (Sandbox Code Playgroud)
我没有太多使用Gradle的经验,编写build.gradle文件的开发人员写的不同于大多数网站提供的示例.
这是build.gradle:
apply plugin: 'java'
apply plugin: 'eclipse'
version = '0.1'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
compile 'placeholder'
}
task release(type: Jar) {
manifest {
attributes("Implementation-Title": "placeholder",
"Implementation-Version": version,
'Main-Class': 'placeholder.Application')
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2.1'
}
Run Code Online (Sandbox Code Playgroud)
我不知道在哪里提出论点.我尝试将它们放在不同的位置,但我总是得到:
A problem occurred evaluating root project 'placeholder'.
> No such property: applicationDefaultJvmArgs for …Run Code Online (Sandbox Code Playgroud) 我想为封装简单Numbers的类创建扩展函数.例如DoubleProperty.我遇到了问题,我不能同时超载+和+=操作员.
我不想创建一个通过以下测试的行为:
class DoublePropertyTest {
lateinit var doubleProperty: DoubleProperty
@Before
fun initialize() {
doubleProperty = SimpleDoubleProperty(0.1)
}
@Test
fun plus() {
val someProperty = doubleProperty + 1.5
assertEquals(someProperty.value, 1.6, 0.001)
}
@Test
fun plusAssign() {
val someProperty = doubleProperty
doubleProperty += 1.5 //error if + and += are overloaded
assert(someProperty === doubleProperty) //fails with only + overloaded
assertEquals(doubleProperty.value, 1.6, 0.001)
}
}
Run Code Online (Sandbox Code Playgroud)
它可以使用这些扩展函数实现:
operator fun ObservableDoubleValue.plus(number: Number): DoubleProperty
= SimpleDoubleProperty(get() + number.toDouble()) …Run Code Online (Sandbox Code Playgroud) 好的,在我开始解释我的问题之前,我想让你知道我知道背后的设计理念Optional,它不打算用于字段或集合,但我已经在Kotlin编程了很多,并且真的不喜欢使用null.
所以我在虚幻引擎中有一个基于节点的编辑器,每个节点都有ConnectionBoxes,它可以是空闲的,也可以被a占用Connection.
因此,有不同的方式来表达这其中之一是利用一张地图,每一个映射ConnectionBox到一个Connection这样的:
Map<ConnectionBox, Connection> connectionEndPoints;
Run Code Online (Sandbox Code Playgroud)
而Connection可能是null,如果ConnectionBox是免费的.我不喜欢这个,因为其他开发人员不知道这个Map的功能,并且它可能会返回null现有的ConnectionBox.
所以我很想用一个:
Map<ConnectionBox, Optional<Connection>> connectionEndPoints;
Run Code Online (Sandbox Code Playgroud)
它显示出更好的打算,你甚至可以读出它:
"这ConnectionBox可能有Connection附加的."
我的问题是:为什么我不应该这样做,即使它更明确地表明意图并阻止NPEs.每个SO帖子和每个博客文章都说这是糟糕的风格,甚至编译器也说我不应该发出警告.
根据要求,这里是一个SO线程,不鼓励使用Optional作为字段或集合值:用于可选
这是警告(因为事实证明它是来自IntelliJ的警告):
警告:可选用作字段{fieldName}的类型
好之后,建议Connection引用应该在ConnectioBox问题的范围内转移.
为什么是:
class ConnectionBox {
Optional<Connection> connection;
...
Run Code Online (Sandbox Code Playgroud)
比...更差
class ConnectionBox {
Connection connection; //may be null
...
Run Code Online (Sandbox Code Playgroud)
除非我发表评论,否则您无法看到您可能会遇到NPE并且我不喜欢解释可以解释自己的代码的评论.
这个问题相当简单:是否可以接收仅触发一次的调整大小事件,即使width同时height更改?
我有一个应用程序,它计算每像素窗口像素大小的图像。当窗口调整大小时,将再次计算图像。问题是,在侦听widthProperty()和 时heightProperty(),总会有两个事件触发,即使width和height在同一个循环周期中更改。这导致了一次冗余计算。有没有办法在每次更新时监听一次调整大小?
一个简单的例子:
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Group root = new Group();
primaryStage.setScene(new Scene(root));
primaryStage.show();
primaryStage.setWidth(800);
primaryStage.setHeight(800);
primaryStage.widthProperty().addListener((observable, oldValue, newValue) ->
System.out.println("old: (" + oldValue + ", " + primaryStage.getHeight() + "); "
+ "new: (" + newValue + ", " + primaryStage.getHeight() …Run Code Online (Sandbox Code Playgroud) 我有一个问题,就是我完全无法使用OpenJDK运行任何jar,而使用普通的OracleJDK则没有问题。
OpenJDK # java -version
openjdk version "1.8.0_101"
OpenJDK Runtime Environment (IcedTea 3.1.0) (suse-14.3-x86_64)
OpenJDK 64-Bit Server VM (build 25.101-b13, mixed mode)
Run Code Online (Sandbox Code Playgroud)
当我使用此JDK运行jar时,即使在清单中也很难找到主类。
OracleJDK # java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
Run Code Online (Sandbox Code Playgroud)
当我使用此JDK启动jar时,没有问题。
我是否需要在OpenJDK中进行配置,以便它可以从清单中找到主类,或者OpenJDK不能这样做是什么?
源文件结构:
-- ui
---- Main.java
Run Code Online (Sandbox Code Playgroud)
Gradle构建脚本:
group 'some.group'
version '0.1'
apply plugin: 'java'
apply plugin: 'application'
mainClassName = "ui.Main"
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.zeromq', name: …Run Code Online (Sandbox Code Playgroud) 我认为这可能是重复的:模式验证:缺少表[hibernate_sequences],但我无法弄清楚。
因此,在我的application.properties文件中,我有此选项:spring.jpa.hibernate.ddl-auto=validate并且收到此错误:
Schema-validation: missing table [game]
为什么我收到这个?
这是我的Game课和User课:
游戏:
@Entity
public class Game {
@Id
@Column(name = "GAME_NUMBER")
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long gameNumber;
private int playerScore;
private int NPCScore;
private Date datetime;
@ManyToOne
@JoinColumn(name="USER_ID")
private User user;
public Game() {}
public Game(int playerScore, int nPCScore, Date datetime) {
super();
this.playerScore = playerScore;
this.NPCScore = nPCScore;
this.datetime = datetime;
}
public User getUser() {
return user;
}
} + getters …Run Code Online (Sandbox Code Playgroud) 我正在编写一个游戏引擎,但在 z 轴上的转换有问题。当我在 z 轴上平移超过 1 个单位时,对象消失。小于 1 的值对其停留在同一位置的对象没有影响。所有其他转换似乎工作正常。
主循环的一部分:
while (unprocessedTime > frameTime) {
rendering = true;
unprocessedTime -= frameTime;
if (window.isClosed()) {
stop();
}
Time::setDelta(frameTime);
game.update();
if (frameCounter >= Time::SECOND) {
std::cout << fps << std::endl;
fps = 0;
frameCounter = 0;
}
}
if (rendering) {
render();
fps++;
}
Run Code Online (Sandbox Code Playgroud)
渲染方法:
void MainController::render() {
window.clear();
game.render();
window.update();
}
Run Code Online (Sandbox Code Playgroud)
游戏更新和渲染方法:
void Game::update() {
tmp += Time::getDelta();
float sinTemp = sin(tmp);
transform.setPos(glm::vec3(0, 0, sinTemp));
}
void Game::render() {
shader.bind();
shader.setUniform("transform", …Run Code Online (Sandbox Code Playgroud) 我正在寻找一个列出哪些供应商确实支持哪种OpenGL扩展的列表。
例如,我想使用ARB_shading_language_include在2013年被接受的,但是在互联网上的各个论坛上,我认为它并未在AMD驱动程序上实现。但是我找不到任何说明支持此扩展的官方文档。
是否存在这样的列表?