티스토리 뷰

들어가기 전.


프로젝트 생성은 spring initializer로 생성하고 javafx를 구현하는 방식으로 개발.

java 11로 오면서 javafx가 분리됨. 따라서 직접 라이브러리를 추가 하는 방법과, gradle을 이용한 방법 두가지 모두 해봄.



직접 라이브러리를 추가 하는 방법.

Project Structure > Library 또는 Global Library에 jar 파일을 추가하고, 추가한 라이브러리를 오른쪽 클릭하여 Add to module로 모듈에 추가해줘야됨.


Gradle을 이용한 방법.

plugins {
id 'org.springframework.boot' version '2.1.2.RELEASE'
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.7' // 추가
}
javafx {
modules = [ 'javafx.controls', 'javafx.fxml' ] // 추가
}
ext{
javafxVersion = '11.0.2'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

compile group: 'org.openjfx', name: 'javafx-controls', version: "${javafxVersion}"
compile group: 'org.openjfx', name: 'javafx-media', version: "${javafxVersion}"
compile group: 'org.openjfx', name: 'javafx-graphics', version: "${javafxVersion}"
compile group: 'org.openjfx', name: 'javafx-fxml', version: "${javafxVersion}"
}


공통


--add-exports=javafx.graphics/com.sun.javafx.util=ALL-UNNAMED

--add-exports=javafx.base/com.sun.javafx.reflect=ALL-UNNAMED


Main

@SpringBootApplication
public class JavafxApplication extends Application {

private ConfigurableApplicationContext springContext;
private Parent rootNode;

public static void main(String[] args) {
Application.launch(args);
}

@Override
public void init() throws Exception {
springContext = SpringApplication.run(JavafxApplication.class);
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
fxmlLoader.setControllerFactory(springContext::getBean);
rootNode = fxmlLoader.load();
}

@Override
public void stop() throws Exception {
springContext.close();
}

@Override
public void start(Stage stage) throws Exception {
stage.setScene(new Scene(rootNode));
stage.show();
}

main.fxml 내용 생략

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함