我最近在eclipse中创建了javafx项目,我在eclipse中成功运行,并且运行良好。 我想使用命令行界面运行我的项目。
我能够成功编译,但无法运行,并且不断显示“错误:找不到或加载主类Main”
Compile command (Works fine):
javac -cp "C:\Program Files (x86)\Oracle\JavaFX 2.2 Runtime\lib\jfxrt.jar" Main.java
Main.class is created after the above command.
Run Command (doesn't work):
java -cp "C:\Program Files (x86)\Oracle\JavaFX 2.2 Runtime\lib\jfxrt.jar;." Main
我想知道为了成功运行它,我在这里缺少什么。
添加Main.java
package application;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
private Stage primaryStage;
private BorderPane root;
@Override
public void start(Stage primaryStage) {
try {
this.primaryStage = primaryStage;
primaryStage.setTitle("Mojo");
initRootLayout();
showMapLayout();
} catch(Exception e) {
e.printStackTrace();
}
}
private void showMapLayout() {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("/application/viewControllers/mapView.fxml"));
AnchorPane mapPane = (AnchorPane)loader.load();
root.setCenter(mapPane);
} catch (IOException e) {
e.printStackTrace();
}
}
private void initRootLayout() {
try{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("/application/viewControllers/RootLayout.fxml"));
root = (BorderPane)loader.load();
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}catch(Exception e){
System.out.println(e.getMessage());
}
}
public static void main(String[] args) {
launch(args);
}
}