簡體   English   中英

如何為我的程序生成一個工作jar文件?

[英]How to generate a working jar file for my program?

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

在eclipse中,您可以右鍵單擊項目名稱

  • 選擇導出
  • 在Java類別中選擇Runable JAR文件
  • 選擇主類的配置(如果沒有找到,你應該先運行你的應用程序)
  • 設置導出目的地
  • select copy要求libs到子文件夾

導出jar時,可以在jar manifest.mf文件中將依賴關系jar指定為Class-Path條目。 您可以在以下鏈接中找到有關此內容的更多詳細信息: http//docs.oracle.com/javase/tutorial/deployment/jar/downman.html 一旦你沒有這個確保相應的從屬罐將在類路徑中。

您可以使用Eclipse IDE生成.jar文件。 您還可以將資源文件(如圖像或媒體文件)添加到.jar中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM