Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的程序在用javapackager编译后';即使使用javac进行编译也无法运行?_Java_Javafx - Fatal编程技术网

为什么我的程序在用javapackager编译后';即使使用javac进行编译也无法运行?

为什么我的程序在用javapackager编译后';即使使用javac进行编译也无法运行?,java,javafx,Java,Javafx,我遇到过这样的问题。这是我的密码: package pdfex; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.StackPane; import ja

我遇到过这样的问题。这是我的密码:

package pdfex;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.control.TextField;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.FileChooser;
import javafx.geometry.*;
import javafx.scene.paint.Color;



import java.io.File;
import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.lang.*;
import java.util.*;
import java.util.HashMap;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.ColumnText;
//import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Element;


public class PdfExport extends Application {
    public static void main(String[] args) {
        launch(args);
    }
    File filePDF;
    File fileCos;
    File fileWmark;

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("PDF Export");

        GridPane grid = new GridPane();
        grid.setAlignment(Pos.CENTER);
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(25, 25, 25, 25));

        Text scenetitle = new Text("PDF Export");
        scenetitle.setFont(Font.font("Tahoma",FontWeight.NORMAL,20));
        grid.add(scenetitle, 0, 0, 2, 1);

        Label openPwd = new Label("Open Password");
        grid.add(openPwd, 0, 1);

        TextField userTextField = new TextField();
        userTextField.getText();
        grid.add(userTextField, 1, 1);

        Label homePwd = new Label("Home Password");
        grid.add(homePwd, 0, 2);

        TextField pwBox = new TextField();
        pwBox.getText();
        grid.add(pwBox, 1, 2);

        Label labelCos = new Label();
        //final String cos = new String();

        Button btnBrowse = new Button("List of Companies");
        final StringBuilder cos = new StringBuilder();

        btnBrowse.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(final ActionEvent e) {
                FileChooser listChooser = new FileChooser();

                //Set filter TEXT file
                FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("TEXT Files (*.txt)", "*.txt");
                listChooser.getExtensionFilters().add(extFilter);

                fileCos = listChooser.showOpenDialog(primaryStage);
                String filePathCos = fileCos.getAbsolutePath();

                labelCos.setText(filePathCos);
                cos.append(filePathCos);

            }
        });



        HBox hbBtnBrowser = new HBox(10);
        hbBtnBrowser.setAlignment(Pos.CENTER);
        hbBtnBrowser.getChildren().addAll(btnBrowse, labelCos);
        grid.add(hbBtnBrowser, 1, 3);


        Label labelPDF = new Label();
        //final String pdf = new String();

        Button btnBrowse2 = new Button("Look for PDF files");
        final StringBuilder pdf = new StringBuilder();  
        btnBrowse2.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent e) {

                FileChooser pdfFile = new FileChooser();

                // Set extension filtre
                FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("PDF Files (*.pdf)", "*.pdf");
                pdfFile.getExtensionFilters().add(extFilter);

                // Show open file dialog
                filePDF = pdfFile.showOpenDialog(primaryStage);

                String filePathPDF = filePDF.getAbsolutePath();

                labelPDF.setText(filePathPDF);
                pdf.append(filePathPDF);
            }   
        });

        HBox hbBtnBrowse2 = new HBox(10);
        hbBtnBrowse2.setAlignment(Pos.CENTER);
        hbBtnBrowse2.getChildren().addAll(btnBrowse2, labelPDF);
        grid.add(hbBtnBrowse2, 1, 4);

        // Watermark File
        Label labelWatermark = new Label();
        //final String wmark = new String();

        Button btnWmark = new Button("Watermark?");
        final StringBuilder wmark = new StringBuilder();
        btnWmark.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent e) {
                FileChooser wmarkFile = new FileChooser();

                fileWmark =  wmarkFile.showOpenDialog(primaryStage);

                String filePathWmark = fileWmark.getAbsolutePath();

                labelWatermark.setText(filePathWmark);
                wmark.append(filePathWmark);
            }
        });

        HBox hbBtnBrowse3 = new HBox(10);
        hbBtnBrowse3.setAlignment(Pos.CENTER);
        hbBtnBrowse3.getChildren().addAll(btnWmark, labelWatermark);
        grid.add(hbBtnBrowse3, 1, 5);



        //grid.setGridLinesVisible(true);

        Button btn = new Button("Exporting PDF");
        HBox hbBtn = new HBox(10);
        hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
        hbBtn.getChildren().add(btn);
        grid.add(hbBtn, 2, 7);



        final Text actiontarget = new Text();
            grid.add(actiontarget, 1, 9);

        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {

                long startTime = System.currentTimeMillis();

                //System.out.println(cos.toString());

                actiontarget.setFill(Color.BLACK);


                try {
                    BufferedReader br = new BufferedReader(new FileReader(cos.toString()));
                    String line;


                    String user = userTextField.getText();
                    byte[] USER = user.getBytes();


                    String owner = pwBox.getText();
                    byte[] OWNER = owner.getBytes();

                    if(user != owner) {

                        try{

                            while ((line = br.readLine()) != null) {

                                try {

                                    String a = line;
                                    PdfReader Post_Survey = new PdfReader(pdf.toString());
                                    int number_of_pages = Post_Survey.getNumberOfPages();

                                    // Naming PDF files
                                    PdfStamper stamp = new PdfStamper(Post_Survey, new FileOutputStream(line + ".pdf"));

                                    // set Security
                                    stamp.setEncryption(USER, OWNER, PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA);


                                    // Update Metadata
                                    HashMap<String, String> hMap = Post_Survey.getInfo();
                                    hMap.put("Title", "Post Survey Highlights");
                                    hMap.put("Subject", "Market Highlights");
                                    hMap.put("Creator", "Zestiremia");
                                    hMap.put("Keywords","                                 \n            * * * * *            \n          *             *          \n        *    * * * *    *        \n       *         *         *       \n       *       *           *       \n       *     * * * *     *       \n        *                 *        \n          *             *          \n      * * * *       * * * *      \n                                 ");
                                    hMap.put("Author", "SSC-Talentnet");
                                    stamp.setMoreInfo(hMap);

                                    int i = 0;

                                    Image watermark_image = Image.getInstance(wmark.toString());
                                    BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ITALIC, BaseFont.WINANSI, BaseFont.EMBEDDED);

                                    watermark_image.setAbsolutePosition(430, 10);
                                    PdfContentByte add_watermark;
                                    PdfContentByte add_text;

                                    //start stamping!!
                                    while (i < number_of_pages) {
                                      i++;


                                      // watermark image
                                      add_watermark = stamp.getOverContent(i);
                                      add_watermark.addImage(watermark_image);

                                      // set where lines are      
                                      add_text = stamp.getOverContent(i);
                                      add_text.setFontAndSize(bf, 12);
                                      ColumnText.showTextAligned(add_text,Element.ALIGN_LEFT, new Phrase("This is the properties of blah blah and is solely used for " + line + " only!"), 20, 20, 0);

                                    }stamp.close();
                                    //Post_Survey.close();
                                }
                                catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }catch (Exception e) {
                            e.printStackTrace();
                        }
                    }   
                }catch (IOException e) {
                    e.printStackTrace();}

                long endTime = System.currentTimeMillis();
                long totalTime = endTime - startTime;

                actiontarget.setText("What up yo! It's all done.\nThe whole process has taken up to "+totalTime/1000+"s.\nYou've done a great job!");   
                //System.out.println("What up yo!!!");

            }
        });

        primaryStage.setScene(new Scene(grid, 550, 300));
        primaryStage.show();

    }

}
`
知道为什么吗?

如果您使用java-jar,您需要引用jar清单中的其他java库

正如tomsontom所说,java运行时正在寻找不可用的类/库

一种流行的方法是将项目设置为使用Maven。Maven可以从中提取库。然后,您可以使用创建.jar,其中包含打包的库


另一个选项是使用另一个构建工具。

忘记了pdf库的类路径?我已经检查了类路径,iText的pdf库就在那里。但我不认为这会发生,因为如果我忘记了,编译将无法运行。正如我所提到的,
javac
java
在没有打包过程的情况下运行良好。您是如何做到的?对不起,我对这些都不熟悉。我希望能够将它作为一个独立的文件运行(通过双击)。所有的IDE都支持打包程序——我是efxclipse的作者,例如它在eclipse中支持打包程序,但NetBeans和IntelliJ也支持打包程序。多功能一体式版本可在
Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: com/itextpdf/text/pdf/PdfReader
        at pdfex.PdfExport$4.handle(PdfExport.java:232)
        at pdfex.PdfExport$4.handle(PdfExport.java:199)
        at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
        at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
        at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
        at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
        at javafx.event.Event.fireEvent(Unknown Source)
        at javafx.scene.Node.fireEvent(Unknown Source)
        at javafx.scene.control.Button.fire(Unknown Source)
        at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
        at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
        at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
        at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
        at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
        at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
        at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
        at javafx.event.Event.fireEvent(Unknown Source)
        at javafx.scene.Scene$MouseHandler.process(Unknown Source)
        at javafx.scene.Scene$MouseHandler.access$1500(Unknown Source)
        at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
        at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
        at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
        at com.sun.glass.ui.View.notifyMouse(Unknown Source)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
        at com.sun.glass.ui.win.WinApplication$$Lambda$37/96639997.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.itextpdf.text.pdf.PdfReader
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 48 more