我已经在intelliJ中创建了Java / JavaFX应用程序。我将其创建为Java应用程序,后来又为JavaFX导入了必要的部分。
我尝试了来自Izpack,Javapackager,Jpackager,Jpackage的各种安装程序/打包程序创建者,并创建了一个胖子jar。什么都不会对我有用。
该应用程序可以在IntelliJ中正常运行。
为什么它不能在其他地方运行?
这是我的POM,代码和错误消息。
如果您能解决此问题,我将支付10美元。
一些特定的错误消息:
胖jar,通过控制台调用jar:> java -cp MLSNUM_to_PUBREC-0.8.7-SNAPSHOT-jar-with-dependencies.jar com.company.Main 错误:缺少JavaFX运行时组件,并且是运行此应用程序所必需的
jpackager:(多个Alert_error窗口)未能找到库/bin/msvcr100.dll,无法找到jni_createJavavm,无法启动JVM
这是我的代码:
package com.company;
import com.gargoylesoftware.htmlunit.*;
import com.gargoylesoftware.htmlunit.html.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import org.apache.bcel.generic.RETURN;
import org.junit.After;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.io.*;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javafx.application.Application;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application{
static WebClient webClient;
static CookieManager cookieManager;
private static String username = "User";
private static String password = "Pass";
static File InputFile;
private static String downloadPubRec;
private static String formattedStringMLS;
private static ArrayList<String> downloadMLSNums;
private static String downloadFinal;
private static ArrayList<String> publicRecordArrayListFinal = new ArrayList<String>();
public void start(Stage stage) throws Exception {
Label l = new Label("MLS2PubRec");
Scene scene = new Scene(new StackPane(l), 640, 480);
stage.setTitle("MLS2PubRec");
FileChooser fileChooser = new FileChooser();
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
Scene scene2 = new Scene(grid, 500, 450);
Text scenetitle = new Text("Welcome!");
scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
grid.add(scenetitle, 0, 0, 2, 1);
Label userName = new Label("Pinergy User Name:");
grid.add(userName, 0, 1);
TextField userTextFieldInputFX = new TextField();
grid.add(userTextFieldInputFX, 1, 1);
Label pw = new Label("Pinergy Password:");
grid.add(pw, 0, 2);
PasswordField pwBoxInputFX = new PasswordField();
grid.add(pwBoxInputFX, 1, 2);
Button btnStartApplication = new Button("Download Public Records");
HBox hbBtn = new HBox(10);
hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
hbBtn.getChildren().add(btnStartApplication);
grid.add(hbBtn, 1, 4);
final Text actiontarget = new Text();
grid.add(actiontarget, 1, 6);
actiontarget.setId("actiontarget");
Button btnFileChoose = new Button("Select MLS# File");
btnFileChoose.setOnAction(e -> {
File selectedFile = fileChooser.showOpenDialog(stage);
InputFile = selectedFile;
});
HBox hbBtn2 = new HBox(12);
hbBtn2.setAlignment(Pos.BOTTOM_CENTER);
hbBtn2.getChildren().add(btnFileChoose);
grid.add(hbBtn2, 0, 4);
btnStartApplication.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
actiontarget.setFill(Color.FIREBRICK);
username = userTextFieldInputFX.getText();
password = pwBoxInputFX.getText();
try {
if(InputFile == null){actiontarget.setText("File not found"); }
else{
actiontarget.setText("");
init(); Date date= new Date();
Format formatter = new SimpleDateFormat("YYYY-MM-dd_hh-mm-ss");
if(download(InputFile)){ actiontarget.setText("File downloaded with name:
MLSNum_to_PubRec" + formatter.format(date) +".csv");
close(); }
else{actiontarget.setText("Error"); close();}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
stage.setScene(scene2);
stage.show();
}
public void init() throws Exception {
webClient = new WebClient(BrowserVersion.CHROME);
cookieManager = new CookieManager();
cookieManager = webClient.getCookieManager();
cookieManager.setCookiesEnabled(true);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setRedirectEnabled(true);
}
public static HtmlPage signIn() throws Exception {
//Acquire location for URI, password, username, submitbutton
HtmlPage page1 = webClient.getPage("http://h3c.mlspin.com/signin.asp");
HtmlButton cookieButton = page1.getFirstByXPath("//*
[@id=\"cookieConsentBootstrapModal\"]/div/div/div[3]/button");
page1 = cookieButton.click();
HtmlForm form = page1.getFormByName("loginform");
HtmlTextInput uName = form.getInputByName("user_name");
HtmlPasswordInput passWord = form.getInputByName("pass");
HtmlButton button = form.getFirstByXPath("//*[@id=\"loginForm\"]/table/tbody/tr[7]/td/button");
uName.setValueAttribute(username);
passWord.setValueAttribute(password);
HtmlPage page2 = button.click();
Thread.sleep(2200);
//If login error , login
if (page2.getUrl().toString().contains("Login_Error")){
System.out.println("Login error, reattempting (User already signed in)");
HtmlButton loginErrorButton =
page2.getFirstByXPath("/html/body/div/table/tbody/tr[2]/td/center/button");
page2 = loginErrorButton.click();
}
System.out.println("Getpage2 as text: " + page2.getUrl().toString());
System.out.println("Results p2 URI " + page2.getPage());
System.out.println("Results p1 URI " + page1.getPage());
if (page2.getUrl().toString().contains("signin.asp")) {
return null;
}
else{return page2;}
}
//Does minor formating, downloads file
public static boolean download(File InputFile) throws Exception {
if (InputFile == null) {
return false;
} else {
HtmlPage page3 = signIn();
HtmlAnchor toolLinkBtn = page3.getFirstByXPath("/html/body/header/section[2]/nav/a[7]");
page3 = toolLinkBtn.click();
HtmlAnchor publicRecordLinkBtn =page3.getFirstByXPath(""/html/body/table/tbody/tr[2]/td[2]");
page3 = publicRecordLinkBtn.click();
List<List<String>> records = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(InputFile))) {
String line;
int iter = 0;
while ((line = br.readLine()) != null) {
String[] values = line.split(",");
records.add(Arrays.asList(values));
formattedStringMLS = Arrays.asList(values).toString()
.replace(",", "") //remove the commas
.replace("[", "") //remove the right bracket
.replace("]", "") //remove the left bracket
.trim(); //remove trailing spaces from partially initialized arrays
System.out.println("MLSNUM Added : " + formattedStringMLS + "");
page3 = (HtmlPage) page3.refresh();
HtmlInput inputMLSNumberBox = page3.getElementByName("List_No");
HtmlElement searchNowBtn = page3.getElementByName("searchnowimg");
inputMLSNumberBox.setValueAttribute(formattedStringMLS);
page3 = searchNowBtn.click();
Thread.sleep(200);
if ((page3.getVisibleText().contains("No Property Matches Found") == false) && (page3.getVisibleText().contains("Error Processing MLS #") == false)) {
HtmlElement selectAllCheckbox = page3.getElementByName("selall");
HtmlAnchor downloadBtn = page3.getAnchorByHref("javascript:DownloadResults('0');");
page3 = selectAllCheckbox.click();
System.out.println(iter);
String downloadTemp = (downloadBtn.click().getWebResponse().getContentAsString());
downloadTemp = downloadTemp.replaceAll("[\\n\\r\\t]+", "");
downloadTemp = downloadTemp.replaceAll("Estimated Tax", "Estimated Tax"+ "\r" +"\"" + formattedStringMLS + "\",");
downloadPubRec = (downloadPubRec + downloadTemp);
}
}
String tempContent = downloadPubRec.replaceAll("Owner_Address", "OwnerAddTemp");
tempContent = tempContent.replaceAll("null", "");
tempContent = tempContent.replaceAll("Address,", ",MLSNumber,Address,");
tempContent = tempContent.replaceAll("OwnerAddTemp", "Owner_Address");
downloadFinal = tempContent;
System.out.println("Testing Length "+ downloadFinal);
Date date = new Date();
Format formatter = new SimpleDateFormat("YYYY-MM-dd_HH-mm-ss");
System.out.println("Done at " + date.toString());
FileWriter writer = new FileWriter(new File("MLSNum_to_PubRec" + formatter.format(date) + ".csv"));
writer.write(downloadFinal);
alertDownloadFinished();
writer.flush();
}
return true;
}
}
@After
public static void close() throws Exception {
webClient.close();
cookieManager.clearCookies();
Thread.sleep(200);
System.exit(0);
}
private static void alertDownloadFinished() {
Date date = new Date();
Format formatter = new SimpleDateFormat("YYYY-MM-dd_hh-mm-ss");
Alert downloadAlert = new Alert(Alert.AlertType.INFORMATION, ""); //new alert object
downloadAlert.setTitle("MLS2PubRec: Public Records Downloaded!"); //warning box title
downloadAlert.setHeaderText("Output Filename: MLSNum_to_PubRec" + formatter.format(date) + ".csv");// Header
//Description of warning
downloadAlert.getDialogPane().setPrefSize(400, 100); //sets size of alert box
downloadAlert.showAndWait();
}
}
我的POM文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>MLSNUM_to_PUBREC</artifactId>
<version>0.8.8-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.company.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-
dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used
for
inheritance merges -->
<phase>package</phase> <!-- bind to the
packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.company.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<configuration>
<mainClass>com.company.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>14</version>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.43.0</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
答案 0 :(得分:0)
@Reizo的评论向我指出了正确的方向。
我将Java应用重新创建为JavaFX应用(IntelliJ的预建设置)
改变了我的总体项目结构,转而使用了应用程序扩展内部没有的主要方法。
我也将所有Java版本都更新为Java 14。
考虑此问题已解决。谢谢@Reizo!我非常感谢您的建议和帮助。