3

我对java很陌生,事实上这是我的第一个程序。我似乎在为我的 java 程序生成 jar 文件时遇到问题。这是一个非常基本的程序,它仅从网站获取数据,然后将其显示在 gui 中。该程序依赖于 Jsoup 和 HtmlCleaner。gui 是用 JFormDesigner 制作的。

回到问题上来,当我使用 eclipse 运行程序时,一切运行良好。没有任何问题。但是,当我将它作为导出的 jar(或使用 Jar Maker 制作的 jar)运行时,GUI 甚至都不会出现。奇怪的是,当我用一个.bat文件运行它时,GUI 会显示,但程序并没有做它应该做的事情。

我真的被卡住了,我不知道下一步该尝试什么。任何帮助将不胜感激。

//package com.stackoverflow.q2835505;


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.awt.*;

import javax.swing.*;

import com.sun.xml.internal.ws.util.StringUtils;

public class TestDumper extends JFrame {
public static String test = "+";
public static String test1 = "-";
public static String itemID;
public static String stab;
public static String slash;
public static String crush;
public static String magic;
public static String range;
public static String stabDef;
public static String slashDef;
public static String crushDef;
public static String magicDef;
public static String rangeDef;
public static String Str;
public static String Prayer;
public static String lowAlch;
public static String highAlch;
public static String Name;
public boolean guiWait = false;
public static boolean printed = true;



    public static void main(String[] args) throws Exception {
        statGrabber g = new statGrabber();
        g.setDefaultCloseOperation(EXIT_ON_CLOSE);
        g.setVisible(true);

        for ( ; ; ) {
        while(g.test){
        String url = g.textField2.getText();
        Document document = Jsoup.connect(url).get();
        stab = document.select("table.wikitable.smallpadding tbody tr td").tagName("TD").eq(2).text();
        slash = document.select("table.wikitable.smallpadding tbody tr td").tagName("TD").eq(3).text();
        crush = document.select("table.wikitable.smallpadding tbody tr td").tagName("TD").eq(4).text();
        magic = document.select("table.wikitable.smallpadding tbody tr td").tagName("TD").eq(5).text();
        range = document.select("table.wikitable.smallpadding tbody tr td").tagName("TD").eq(6).text();
        stabDef = document.select("table.wikitable.smallpadding tbody tr td").tagName("TD").eq(7).text();
        slashDef = document.select("table.wikitable.smallpadding tbody tr td").tagName("TD").eq(8).text();
        crushDef = document.select("table.wikitable.smallpadding tbody tr td").tagName("TD").eq(9).text();
        magicDef = document.select("table.wikitable.smallpadding tbody tr td").tagName("TD").eq(10).text();
        rangeDef = document.select("table.wikitable.smallpadding tbody tr td").tagName("TD").eq(11).text();
        Str = document.select("table.wikitable.smallpadding tbody tr td").tagName("TD").eq(16).text();
        Prayer = document.select("table.wikitable.smallpadding tbody tr td").tagName("TD").eq(17).text();
        Name = document.select("table.wikitable.infobox caption b").text();
        highAlch = document.select("table.wikitable.infobox tbody tr td").tagName("TD").eq(8).text();
        lowAlch =  document.select("table.wikitable.infobox tbody tr td").tagName("TD").eq(9).text();
        g.sweet = true;
       // String shopPrice = document.select("table.wikitable.infobox tbody tr td").tagName("TD").eq(11).text();


       if(stab.startsWith(test)){
           stab = stab.substring(1);
       }
       if(slash.startsWith(test)){
           slash = slash.substring(1);
       }
       if(crush.startsWith(test)){
           crush = crush.substring(1);
       }
       if(magic.startsWith(test)){
           magic.trim();
           magic = magic.substring(1);
       }
       if(range.startsWith(test)){
           range.trim();
           range = range.substring(1);
       }
       if(stabDef.startsWith(test)){
           stabDef = stabDef.substring(1);
       }
       if(slashDef.startsWith(test)){
           slashDef = slashDef.substring(1);
       }
       if(crushDef.startsWith(test)){
           crushDef = crushDef.substring(1);
       }
       if(magicDef.startsWith(test)){
           magicDef.trim();
           magicDef = magicDef.substring(1);
       }
       if(rangeDef.startsWith(test)){
           rangeDef.trim();
           rangeDef = rangeDef.substring(1);
       }
       if(Str.startsWith(test)){
           Str.trim();
           Str = Str.substring(1);
       }
       if(Prayer.startsWith(test)){
           Prayer.trim();
           Prayer = Prayer.substring(1);
       }


       if(highAlch.equalsIgnoreCase("Cannot be alchemised")){
           highAlch = "0";
           lowAlch = "0";
       }
       else{
           highAlch = highAlch.replace(",", "");
           highAlch = highAlch.replace(" ", "");
           highAlch = highAlch.replace("c", "");
           highAlch = highAlch.replace("o", "");
           highAlch = highAlch.replace("i", "");
           highAlch = highAlch.replace("n", "");
           highAlch = highAlch.replace("s", "");

           lowAlch = lowAlch.replace(",", "");
           lowAlch = lowAlch.replace(" ", "");
           lowAlch = lowAlch.replace("c", "");
           lowAlch = lowAlch.replace("o", "");
           lowAlch = lowAlch.replace("i", "");
           lowAlch = lowAlch.replace("n", "");
           lowAlch = lowAlch.replace("s", "");
       }

       while(printed){
        System.out.print("item = "+ itemID+"\t");
        System.out.print(Name.replace(" ", "_")+"\t");
        System.out.print(Name.replace(" ", "_")+"\t");
        System.out.print(highAlch+"\t");
        System.out.print(lowAlch+"\t");
        System.out.print("0\t");
        System.out.print(stab+"\t");
        System.out.print(slash+"\t");
        System.out.print(crush+"\t");
        System.out.print(magic+"\t");
        System.out.print(range+"\t");
        System.out.print(stabDef+"\t");
        System.out.print(slashDef+"\t");
        System.out.print(crushDef+"\t");
        System.out.print(magicDef+"\t");
        System.out.print(rangeDef+"\t");
        System.out.print(Str+"\t");
        System.out.print(Prayer+"\n");
        System.out.print("Connected!\n");
        printed = false;
       }
        }
    }
    }
    }  
4

3 回答 3

1

在eclipse中,您可以右键单击项目名称

  • 选择导出
  • 在 Java 类别中选择 Runable JAR 文件
  • 选择主类的配置(如果没有找到,你应该先运行你的应用程序)
  • 设置导出目的地
  • 选择将需要的库复制到子文件夹中
  • 结束
于 2012-05-16T08:44:45.570 回答
0

导出 jar 时,可以在 jar manifest.mf 文件中将依赖 jar 指定为 Class-Path 条目。您可以在此链接中找到更多详细信息:http: //docs.oracle.com/javase/tutorial/deployment/jar/downman.html。一旦你没有这样做,请确保相应的依赖 jar 将在类路径中。

于 2012-05-16T08:01:16.497 回答
0

您可以使用 Eclipse IDE 生成 .jar 文件。您还可以将图像或媒体文件等资源文件添加到 .jar 中。

于 2012-05-18T08:28:15.297 回答