2012-10-22 98 views
3

我是JavaFX的新手。我使用maven創建了一個Hello World項目。在Eclipse中運行它時它工作正常。如何使用maven構建可運行的JavaFX應用程序?

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

@Override 
public void start(Stage primaryStage) throws Exception { 
    primaryStage.setTitle("Hello World!"); 
    Button btn = new Button(); 
    btn.setText("Say 'Hello World'"); 
    btn.setOnAction(new EventHandler<ActionEvent>() { 
     public void handle(ActionEvent event) { 
      System.out.println("Hello World!"); 
     } 
    }); 
    StackPane root = new StackPane(); 
    root.getChildren().add(btn); 
    primaryStage.setScene(new Scene(root, 300, 250)); 
    primaryStage.show(); 
} 

hello_world

我發現deployment tutorial,但是當我的程序自帶Maven的,我不知道如何來構建它。

當我嘗試使用build.fxbuild構建應用程序時,出現此錯誤。

 
Buildfile: C:\test\project\workspace\javafx-helloworld\build\build.xml 

setup-staging-area: 
     [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\externalLibs 
     [copy] Copying 1 file to C:\test\project\workspace\javafx-helloworld\build\externalLibs 
     [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\project 
     [copy] Copying 1 file to C:\test\project\workspace\javafx-helloworld\build\project 
     [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\projectRefs 

do-compile: 
     [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\build\src 
     [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\build\libs 
     [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\build\classes 
     [copy] Copying 1 file to C:\test\project\workspace\javafx-helloworld\build\build\libs 
     [copy] Copying 1 file to C:\test\project\workspace\javafx-helloworld\build\build\src 
     [javac] Compiling 1 source file to C:\test\project\workspace\javafx-helloworld\build\build\classes 

init-fx-tasks: 
    [taskdef] Could not load definitions from resource com/sun/javafx/tools/ant/antlib.xml. It could not be found. 

do-deploy: 
     [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\dist 
     [mkdir] Created dir: C:\test\project\workspace\javafx-helloworld\build\dist\libs 
     [copy] Copying 1 file to C:\test\project\workspace\javafx-helloworld\build\dist\libs 

**BUILD FAILED 
C:\test\project\workspace\javafx-helloworld\build\build.xml:93: Problem: failed to create task or type javafx:com.sun.javafx.tools.ant:resources 
Cause: The name is undefined. 
Action: Check the spelling. 
Action: Check that any custom tasks/types have been declared. 
Action: Check that any/declarations have taken place. 
No types or tasks have been defined in this namespace yet** 
+0

你真的是* * Maven的,而不是如螞蟻? –

+0

我更喜歡使用Maven,但我不知道如何構建它。 – Drogba

+0

哦,我明白了。所以你的任務是將當前用Ant構建的項目轉換爲Maven項目? –

回答

4

現在有JavaFX的Maven插件:

https://github.com/zonski/javafx-maven-plugin

<plugin> 
    <groupId>com.zenjava</groupId> 
    <artifactId>javafx-maven-plugin</artifactId> 
    <version>1.1</version> 
    <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>package</goal> 
      </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <mainClass>[put your application main class here]</mainClass> 
     <bundleType>ALL</bundleType> 
    </configuration> 
</plugin> 
相關問題