我当前在Java代码中为VBS script
添加了hMailServer
,以在启动JavaMail客户端之前配置服务器。所有工作都通过eclipse完成,但是当我导出到可执行jar时,我认为文件路径错误。例如,通过日食,我看到cscript C:\Users\username\Desktop\RadioWithEmail\target\classes\script\hmail-create-account1.vbs user password test.au
效果很好。
从可执行的jar我得到
cscript file:\C:\Users\username\Desktop\NeoChat.jar!\script\hmail-create-account1.vbs user password test.au
下面是我的代码。我在获取文件路径时犯了什么错误?任何意见欢迎。预先感谢。
public class emailLogin {
private Stage primaryStage;
private PersistenceAccess persistenceAccess = new PersistenceAccess();
private User me;
private Settings settings;
private EmailManager emailManager = new EmailManager(settings);
private File f;
private MainUiController ui;
public emailLogin(Stage stage, final Settings settings, MainUiController ui) throws Exception {
this.settings = settings;
this.ui = ui;
me = settings.getMe();
String user = me.getNick();
String ip = me.getIpAddress();
String emailaddress = user + "@" + ip;
/* Routine to bring the account onto hMailserver */
f = new File(getClass().getResource("/script/hmail-create-account1.vbs").getFile());
// String path = f.getPath();
// String pathto =('"'+path+'"');
System.out.println("cscript " + f + " " + user + " " + "password" + " " + ip);
Runtime.getRuntime().exec("cscript " + f + " " + user + " " + "password" + " " + ip);
ViewFactory viewFactory = new ViewFactory(emailManager);
List<ValidAccount> validAccounts = persistenceAccess.loadFromPersistence();
if (validAccounts.size() > 0) {
viewFactory.showMainWindow(settings, ui);
for (ValidAccount validAccount : validAccounts) {
EmailAccount emailAccountupdate = new EmailAccount(validAccount.getAddress(),
validAccount.getPassword(), me.getIpAddress());
LoginService loginService = new LoginService(emailAccountupdate, emailManager, settings, ui);
loginService.start();
}
} else {
viewFactory.showLoginWindow(settings, ui);
}
}
public void stop() throws Exception {
List<ValidAccount> validAccounts = new ArrayList<ValidAccount>();
for (EmailAccount emailAccount : emailManager.getEmailAccounts()) {
validAccounts.add(new ValidAccount(emailAccount.getAddress(), emailAccount.getPassword()));
}
persistenceAccess.savePersistence(validAccounts);
}
}