我在NetBeans中工作,试图编写一个使用第三方库连接到远程系统的简单JavaFX应用程序。该库名为asjava.zip
,它包含一个UniObjects
命名空间。
如果我在控制台或(urgh)Swing应用程序中使用它,它将像这样运行:
import asjava.uniobjects.*;
public class JFLogin extends javax.swing.JFrame {
protected UniSession session;
... Swing UI removed ...
private void cmdLoginActionPerformed(java.awt.event.ActionEvent evt) {
try{
session = new UniSession();
session.setHostName(txtHost.getText());
session.setUserName(txtUser.getText());
session.setAccountPath(txtPath.getText());
session.setPassword(txtPass.getText());
session.connect();
lblStatus.setText("Connected");
}catch(Exception e){
lblStatus.setText(e.getMessage());
}
}
我将asjava.zip
作为库添加到了项目中,并且工作正常。
如果我在JavaFX中使用FXML文件定义登录表单,请执行相同的操作。这是xml,请注意,我已经在这里以及控制器中导入了库:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import asjava.uniobjects.*?>
<AnchorPane id="AnchorPane" prefHeight="525.0" prefWidth="700.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/10.0.1" fx:controller="fxbooks.FXMLDocumentController">
<children>
<Label fx:id="label" layoutX="126" layoutY="120" minHeight="16" minWidth="69" />
<SplitPane dividerPositions="0.27890173410404623" layoutY="-2.0" prefHeight="525.0" prefWidth="694.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="523.0" prefWidth="180.0" style="-fx-background-color: black;">
<children>
<Button fx:id="cmdShowTitles" layoutX="50.0" layoutY="27.0" mnemonicParsing="false" onAction="#handleTitleButtonAction" text="Show Titles" />
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="523.0" prefWidth="515.0">
<children>
<Button fx:id="button" layoutX="345.0" layoutY="432.0" onAction="#handleButtonAction" text="Connect" />
<Label layoutX="24.0" layoutY="84.0" text="Host name : " />
<Label layoutX="27.0" layoutY="124.0" text="Account Path : " />
<Label layoutX="24.0" layoutY="173.0" text="User name : " />
<Label layoutX="27.0" layoutY="214.0" text="Password : " />
<TextField fx:id="txtHost" layoutX="129.0" layoutY="79.0" />
<TextField fx:id="txtPath" layoutX="129.0" layoutY="119.0" />
<TextField fx:id="txtUser" layoutX="129.0" layoutY="168.0" />
<TextField fx:id="txtPass" layoutX="129.0" layoutY="209.0" />
<Label fx:id="lblMessage" layoutX="147.0" layoutY="482.0" />
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
以及控制器代码:
...
import asjava.uniobjects.*;
...
@FXML
private void handleButtonAction(ActionEvent event) {
try{
session = new UniSession();
session.setHostName(txtHost.getText());
session.setUserName(txtUser.getText());
session.setAccountPath(txtPath.getText());
session.setPassword(txtPass.getText());
session.connect();
lblMessage.setText("Connected");
}catch(Exception e){
lblMessage.setText(e.getMessage());
}
}
运行此命令时,会从启动器中为asjava.UniObjects.UniSession
引发ClassNotFoundException。我尝试从指定类路径的命令行手动运行此命令,但遇到相同的错误。
如果我将UniSession
封装在另一个类(例如Connection类)中,则它将起作用,直到我单击按钮,并且启动器的回调会引发相同的ClassNotFoundException。
我想念什么?
谢谢!