如何为我的程序生成一个工作jar文件?

时间:2012-05-16 07:14:16

标签: java jar jsoup

我对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;
       }
        }
    }
    }
    }  

3 个答案:

答案 0 :(得分:1)

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

  • 选择导出
  • 在Java类别中选择Runable JAR file
  • 选择主类的配置(如果找不到,您应该先运行您的应用程序)
  • 设置导出目的地
  • 选择副本需要libs到子文件夹
  • 光洁度

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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