Jar 找不到主方法 - 连接到主类,但无法访问方法

发布于 2024-09-07 07:52:41 字数 17401 浏览 4 评论 0原文

我一直在 Eclipse 中开发一个项目,除了一些 Ant 问题之外,一切都很顺利。

我的代码编译完美,并且完全按照我想要的方式执行,但是,当它在 jar 中时,我收到错误:

Exception in thread "main" java.lang.NoSuchMethodError: main

Main 肯定存在于文件中,所以我的猜测是它与文件的构造方式有关。我一直在使用 SuperCSV 来阅读我拥有的一些 Excel 工作表,并围绕网站上的示例构建了我的主类: http://supercsv.sourceforge.net/codeExamples_general.html。这是我的改编:

ExcelFile.java

package jab.jm.main;

import jab.jm.readers.FileManager;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;

import junit.framework.Test;

import org.supercsv.cellprocessor.constraint.StrMinMax;
import org.supercsv.cellprocessor.ift.CellProcessor;
import org.supercsv.io.CsvBeanReader;
import org.supercsv.io.ICsvBeanReader;
import org.supercsv.prefs.CsvPreference;

class ReadingObjects {

    static final CellProcessor[] userProcessors = { null,
            new StrMinMax(0, 100), null, new StrMinMax(0, 100), null,
            new StrMinMax(0, 100), null, null, null, null, null, null, null,
            null, null, null, null, null, null, null, null, null, null, null,
            null, null, null, null, null, new StrMinMax(0, 100), null,
            new StrMinMax(0, 100), null, null, null, null, null, null, null,
            null, null, null, null, null, null, null, null, null, null, null,
            null, null, null, null, null, null, null, null, null };


    public static void main(String[] args) throws Exception {
        ICsvBeanReader inFile = new CsvBeanReader(
                new FileReader(
                        "C:\\Users\\Justian\\workspaces\\LNConnectionCompiler\\src\\jab\\jm\\main\\Fred_Jewell.csv"),
                CsvPreference.EXCEL_PREFERENCE);
        try {
            final String[] header = { "title", "firstName", "middleName",
                    "lastName", "suffix", "email", "email2", "email3",
                    "businessStreet", "businessStreet2", "businessStreet3",
                    "businessCity", "businessState", "businessPostalCode",
                    "businessCountry", "homeStreet", "homeStreet2",
                    "homeStreet3", "homeCity", "homeState", "homePostalCode",
                    "homeCountry", "otherStreet", "otherStreet2",
                    "otherStreet3", "otherCity", "otherState",
                    "otherPostalCode", "otherCountry", "company", "department",
                    "jobTitle", "assistantPhone", "businessFax",
                    "businessPhone", "businessPhone2", "callback", "carPhone",
                    "companyMainPhone", "homeFax", "homePhone", "homePhone2",
                    "isdn", "mobilePhone", "otherFax", "otherPhone", "pager",
                    "primaryPhone", "radioPhone", "TTYTTDPhone", "telex",
                    "assistantName", "birthday", "managerName", "notes",
                    "otherPOBox", "spouse", "webPage", "personalWebPage" };
            ExcelFile file;
            while ((file = inFile.read(ExcelFile.class, header, userProcessors)) != null) {
                if (file.getCompany().indexOf("Jabian") >= 0)
                    System.out.println(file.getFirstName() + " " + file.getLastName());
            }
        } finally {
            inFile.close();
        }

        URL location = ExcelFile.class.getProtectionDomain().getCodeSource().getLocation();
        System.out.println(location.getFile());

    }
}

public class ExcelFile {
    private String title, firstName, middleName, lastName, suffix, email,
            email2, email3, businessStreet, businessStreet2, businessStreet3,
            businessCity, businessState, businessPostalCode, businessCountry,
            homeStreet, homeStreet2, homeStreet3, homeCity, homeState,
            homePostalCode, homeCountry, otherStreet, otherStreet2,
            otherStreet3, otherCity, otherState, otherPostalCode, otherCountry,
            company, department, jobTitle, assistantPhone, businessFax,
            businessPhone, businessPhone2, callback, carPhone,
            companyMainPhone, homeFax, homePhone, homePhone2, isdn,
            mobilePhone, otherFax, otherPhone, pager, primaryPhone, radioPhone,
            TTYTTDPhone, telex, assistantName, birthday, managerName, notes,
            otherPOBox, spouse, webPage, personalWebPage;

    public String getTitle() {
        return title;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getMiddleName() {
        return middleName;
    }

    public String getLastName() {
        return lastName;
    }

    public String getSuffix() {
        return suffix;
    }

    public String getEmail() {
        return email;
    }

    public String getEmail2() {
        return email2;
    }

    public String getEmail3() {
        return email3;
    }

    public String getBusinessStreet() {
        return businessStreet;
    }

    public String getBusinessStreet2() {
        return businessStreet2;
    }

    public String getBusinessStreet3() {
        return businessStreet3;
    }

    public String getBusinessCity() {
        return businessCity;
    }

    public String getBusinessState() {
        return businessState;
    }

    public String getBusinessPostalCode() {
        return businessPostalCode;
    }

    public String getBusinessCountry() {
        return businessCountry;
    }

    public String getHomeStreet() {
        return homeStreet;
    }

    public String getHomeStreet2() {
        return homeStreet2;
    }

    public String getHomeStreet3() {
        return homeStreet3;
    }

    public String getHomeCity() {
        return homeCity;
    }

    public String getHomeState() {
        return homeState;
    }

    public String getHomePostalCode() {
        return homePostalCode;
    }

    public String getHomeCountry() {
        return homeCountry;
    }

    public String getOtherStreet() {
        return otherStreet;
    }

    public String getOtherStreet2() {
        return otherStreet2;
    }

    public String getOtherStreet3() {
        return otherStreet3;
    }

    public String getOtherCity() {
        return otherCity;
    }

    public String getOtherState() {
        return otherState;
    }

    public String getOtherPostalCode() {
        return otherPostalCode;
    }

    public String getOtherCountry() {
        return otherCountry;
    }

    public String getCompany() {
        return company;
    }

    public String getDepartment() {
        return department;
    }

    public String getJobTitle() {
        return jobTitle;
    }

    public String getAssistantPhone() {
        return assistantPhone;
    }

    public String getBusinessFax() {
        return businessFax;
    }

    public String getBusinessPhone() {
        return businessPhone;
    }

    public String getBusinessPhone2() {
        return businessPhone2;
    }

    public String getCallBack() {
        return callback;
    }

    public String getCarPhone() {
        return carPhone;
    }

    public String getCompanyMainPhone() {
        return companyMainPhone;
    }

    public String getHomeFax() {
        return homeFax;
    }

    public String getHomePhone() {
        return homePhone;
    }

    public String getHomePhone2() {
        return homePhone2;
    }

    public String getISDN() {
        return isdn;
    }

    public String getMobilePhone() {
        return mobilePhone;
    }

    public String getOtherFax() {
        return otherFax;
    }

    public String getOtherPhone() {
        return otherPhone;
    }

    public String getPager() {
        return pager;
    }

    public String getPrimaryPhone() {
        return primaryPhone;
    }

    public String getRadioPhone() {
        return radioPhone;
    }

    public String getTTYTTDPhone() {
        return TTYTTDPhone;
    }

    public String getTelex() {
        return telex;
    }

    public String getAssistantName() {
        return assistantName;
    }

    public String getBirthday() {
        return birthday;
    }

    public String getManagerName() {
        return managerName;
    }

    public String getNotes() {
        return notes;
    }

    public String getOtherPOBox() {
        return otherPOBox;
    }

    public String getSpouse() {
        return spouse;
    }

    public String getWebPage() {
        return webPage;
    }

    public String getPersonalWebPage() {
        return personalWebPage;
    }

    public void setTitle(final String title) {
        this.title = title;
    }

    public void setFirstName(final String firstName) {
        this.firstName = firstName;
    }

    public void setMiddleName(final String middleName) {
        this.middleName = middleName;
    }

    public void setLastName(final String lastName) {
        this.lastName = lastName;
    }

    public void setSuffix(final String suffix) {
        this.suffix = suffix;
    }

    public void setEmail(final String email) {
        this.email = email;
    }

    public void setEmail2(final String email2) {
        this.email2 = email2;
    }

    public void setEmail3(final String email3) {
        this.email3 = email3;
    }

    public void setBusinessStreet(final String businessStreet) {
        this.businessStreet = businessStreet;
    }

    public void setBusinessStreet2(final String businessStreet2) {
        this.businessStreet2 = businessStreet2;
    }

    public void setBusinessStreet3(final String businessStreet3) {
        this.businessStreet3 = businessStreet3;
    }

    public void setBusinessCity(final String businessCity) {
        this.businessCity = businessCity;
    }

    public void setBusinessState(final String businessState) {
        this.businessState = businessState;
    }

    public void setBusinessPostalCode(final String businessPostalCode) {
        this.businessPostalCode = businessPostalCode;
    }

    public void setBusinessCountry(final String businessCountry) {
        this.businessCountry = businessCountry;
    }

    public void setHomeStreet(final String homeStreet) {
        this.homeStreet = homeStreet;
    }

    public void setHomeStreet2(final String homeStreet2) {
        this.homeStreet2 = homeStreet2;
    }

    public void setHomeStreet3(final String homeStreet3) {
        this.homeStreet3 = homeStreet3;
    }

    public void setHomeCity(final String homeCity) {
        this.homeCity = homeCity;
    }

    public void setHomeState(final String homeState) {
        this.homeState = homeState;
    }

    public void setHomePostalCode(final String homePostalCode) {
        this.homePostalCode = homePostalCode;
    }

    public void setHomeCountry(final String homeCountry) {
        this.homeCountry = homeCountry;
    }

    public void setOtherStreet(final String otherStreet) {
        this.otherStreet = otherStreet;
    }

    public void setOtherStreet2(final String otherStreet2) {
        this.otherStreet2 = otherStreet2;
    }

    public void setOtherStreet3(final String otherStreet3) {
        this.otherStreet3 = otherStreet3;
    }

    public void setOtherCity(final String otherCity) {
        this.otherCity = otherCity;
    }

    public void setOtherState(final String otherState) {
        this.otherState = otherState;
    }

    public void setOtherPostalCode(final String otherPostalCode) {
        this.otherPostalCode = otherPostalCode;
    }

    public void setOtherCountry(final String otherCountry) {
        this.otherCountry = otherCountry;
    }

    public void setCompany(final String company) {
        this.company = company;
    }

    public void setDepartment(final String department) {
        this.department = department;
    }

    public void setJobTitle(final String jobTitle) {
        this.jobTitle = jobTitle;
    }

    public void setAssistantPhone(final String assistantPhone) {
        this.assistantPhone = assistantPhone;
    }

    public void setBusinessFax(final String businessFax) {
        this.businessFax = businessFax;
    }

    public void setBusinessPhone(final String businessPhone) {
        this.businessPhone = businessPhone;
    }

    public void setBusinessPhone2(final String businessPhone2) {
        this.businessPhone2 = businessPhone2;
    }

    public void setCallback(final String callback) {
        this.callback = callback;
    }

    public void setCarPhone(final String carPhone) {
        this.carPhone = carPhone;
    }

    public void setCompanyMainPhone(final String companyMainPhone) {
        this.companyMainPhone = companyMainPhone;
    }

    public void setHomeFax(final String homeFax) {
        this.homeFax = homeFax;
    }

    public void setHomePhone(final String homePhone) {
        this.homePhone = homePhone;
    }

    public void setHomePhone2(final String homePhone2) {
        this.homePhone2 = homePhone2;
    }

    public void setIsdn(final String isdn) {
        this.isdn = isdn;
    }

    public void setMobilePhone(final String mobilePhone) {
        this.mobilePhone = mobilePhone;
    }

    public void setOtherFax(final String otherFax) {
        this.otherFax = otherFax;
    }

    public void setOtherPhone(final String otherPhone) {
        this.otherPhone = otherPhone;
    }

    public void setPager(final String pager) {
        this.pager = pager;
    }

    public void setPrimaryPhone(final String primaryPhone) {
        this.primaryPhone = primaryPhone;
    }

    public void setRadioPhone(final String radioPhone) {
        this.radioPhone = radioPhone;
    }

    public void setTTYTTDPhone(final String TTYTTDPhone) {
        this.TTYTTDPhone = TTYTTDPhone;
    }

    public void setTelex(final String telex) {
        this.telex = telex;
    }

    public void setAssistantName(final String assistantName) {
        this.assistantName = assistantName;
    }

    public void setBirthday(final String birthday) {
        this.birthday = birthday;
    }

    public void setManagerName(final String managerName) {
        this.managerName = managerName;
    }

    public void setNotes(final String notes) {
        this.notes = notes;
    }

    public void setOtherPOBox(final String otherPOBox) {
        this.otherPOBox = otherPOBox;
    }

    public void setSpouse(final String spouse) {
        this.spouse = spouse;
    }

    public void setWebPage(final String webPage) {
        this.webPage = webPage;
    }

    public void setPersonalWebPage(final String personalWebPage) {
        this.personalWebPage = personalWebPage;
    }

}

在我看来,这是一个糟糕的结构,但它是完全可能的,这就是为什么我没有遇到任何编译问题。当然,由于它的结构如此不寻常,Ant 可能在尝试访问它时遇到困难。

请注意,ExcelFile.Java 包含非公共类 ReadingObjects,其中包含 main 方法。我的理论是,因为 ExcelFile.java 不一定是包含 main 方法的类,所以我遇到了问题

让我知道你们的想法。我愿意尝试一下。

非常感谢!

-Justian

编辑:这是我的构建文件:

<?xml version="1.0" ?>

<project name="ServerJar" default="dist" basedir=".">
    <description>
        Builds client files into .jar
    </description>
    <!-- [build variables] -->
    <property name="src" location="src" />
    <property name="build" location="build" />
    <property name="dist" location="dist" />
    <property name="lib" location="lib" />
    <!-- [path to packages] -->
    <path id="master-classpath">
        <fileset dir="${lib}">
            <include name="*.jar"/>
        </fileset>
    </path>


    <target name="init">
        <!-- makes time stamp to be used in jar name -->
        <tstamp />
        <!-- creates build directory structure -->
        <mkdir dir="${build}" />
    </target>

    <target name="compile" depends="init" description="Compiles the source">
        <!-- compiles the java code from ${src} into ${build} -->
        <!-- <javac srcdir="${src}" destdir="${build}" /> -->
        <javac destdir= "${build}">
            <src path="${src}"/>
            <classpath refid="master-classpath"/>
        </javac>
    </target>

    <target name="dist" depends="compile" description="Generates distributable">
    <!-- creates the distribution directory -->
        <mkdir dir="${dist}/lib" />

        <!-- puts everything in ${build} into the jar file -->
        <jar jarfile="${dist}/lib/CC-${DSTAMP}.jar" basedir="${build}">
            <manifest>
                <attribute name="Main-Class" value="jab.jm.main.ExcelFile" />
            </manifest>
        </jar>

        <!-- makes a jar file for quick test execution -->
        <jar jarfile="${dist}/lib/CC.jar" basedir="${build}">
            <manifest>
                <attribute name="Main-Class" value="jab.jm.main.ExcelFile" />
            </manifest>
        </jar>
    </target>

    <target name="clean" description="Cleans up the extra build files">
        <!-- deletes the ${build} and ${dist} directories -->
        <delete dir="${build}" />
        <delete dir="${dist}" />
    </target>
</project>

编辑:一切都没有运气。也许我们可以考虑将我的一个文件重新组织为两个文件?

我对此有点紧张,因为我不知道 SuperCSV 需要哪种格式。

I've been working on a project in Eclipse and everything's been going smooth except for some Ant issues along the way.

My code compiles perfectly and does exactly what I want it to do, but, when it's in a jar, I get the error:

Exception in thread "main" java.lang.NoSuchMethodError: main

Main definitely exists in the file, so my guess is that it has to do with the way the file is constructed. I've been using SuperCSV to read some excel sheets I have and have constructed my main class around the example from the website: http://supercsv.sourceforge.net/codeExamples_general.html. Here's my adaptation:

ExcelFile.java

package jab.jm.main;

import jab.jm.readers.FileManager;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;

import junit.framework.Test;

import org.supercsv.cellprocessor.constraint.StrMinMax;
import org.supercsv.cellprocessor.ift.CellProcessor;
import org.supercsv.io.CsvBeanReader;
import org.supercsv.io.ICsvBeanReader;
import org.supercsv.prefs.CsvPreference;

class ReadingObjects {

    static final CellProcessor[] userProcessors = { null,
            new StrMinMax(0, 100), null, new StrMinMax(0, 100), null,
            new StrMinMax(0, 100), null, null, null, null, null, null, null,
            null, null, null, null, null, null, null, null, null, null, null,
            null, null, null, null, null, new StrMinMax(0, 100), null,
            new StrMinMax(0, 100), null, null, null, null, null, null, null,
            null, null, null, null, null, null, null, null, null, null, null,
            null, null, null, null, null, null, null, null, null };


    public static void main(String[] args) throws Exception {
        ICsvBeanReader inFile = new CsvBeanReader(
                new FileReader(
                        "C:\\Users\\Justian\\workspaces\\LNConnectionCompiler\\src\\jab\\jm\\main\\Fred_Jewell.csv"),
                CsvPreference.EXCEL_PREFERENCE);
        try {
            final String[] header = { "title", "firstName", "middleName",
                    "lastName", "suffix", "email", "email2", "email3",
                    "businessStreet", "businessStreet2", "businessStreet3",
                    "businessCity", "businessState", "businessPostalCode",
                    "businessCountry", "homeStreet", "homeStreet2",
                    "homeStreet3", "homeCity", "homeState", "homePostalCode",
                    "homeCountry", "otherStreet", "otherStreet2",
                    "otherStreet3", "otherCity", "otherState",
                    "otherPostalCode", "otherCountry", "company", "department",
                    "jobTitle", "assistantPhone", "businessFax",
                    "businessPhone", "businessPhone2", "callback", "carPhone",
                    "companyMainPhone", "homeFax", "homePhone", "homePhone2",
                    "isdn", "mobilePhone", "otherFax", "otherPhone", "pager",
                    "primaryPhone", "radioPhone", "TTYTTDPhone", "telex",
                    "assistantName", "birthday", "managerName", "notes",
                    "otherPOBox", "spouse", "webPage", "personalWebPage" };
            ExcelFile file;
            while ((file = inFile.read(ExcelFile.class, header, userProcessors)) != null) {
                if (file.getCompany().indexOf("Jabian") >= 0)
                    System.out.println(file.getFirstName() + " " + file.getLastName());
            }
        } finally {
            inFile.close();
        }

        URL location = ExcelFile.class.getProtectionDomain().getCodeSource().getLocation();
        System.out.println(location.getFile());

    }
}

public class ExcelFile {
    private String title, firstName, middleName, lastName, suffix, email,
            email2, email3, businessStreet, businessStreet2, businessStreet3,
            businessCity, businessState, businessPostalCode, businessCountry,
            homeStreet, homeStreet2, homeStreet3, homeCity, homeState,
            homePostalCode, homeCountry, otherStreet, otherStreet2,
            otherStreet3, otherCity, otherState, otherPostalCode, otherCountry,
            company, department, jobTitle, assistantPhone, businessFax,
            businessPhone, businessPhone2, callback, carPhone,
            companyMainPhone, homeFax, homePhone, homePhone2, isdn,
            mobilePhone, otherFax, otherPhone, pager, primaryPhone, radioPhone,
            TTYTTDPhone, telex, assistantName, birthday, managerName, notes,
            otherPOBox, spouse, webPage, personalWebPage;

    public String getTitle() {
        return title;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getMiddleName() {
        return middleName;
    }

    public String getLastName() {
        return lastName;
    }

    public String getSuffix() {
        return suffix;
    }

    public String getEmail() {
        return email;
    }

    public String getEmail2() {
        return email2;
    }

    public String getEmail3() {
        return email3;
    }

    public String getBusinessStreet() {
        return businessStreet;
    }

    public String getBusinessStreet2() {
        return businessStreet2;
    }

    public String getBusinessStreet3() {
        return businessStreet3;
    }

    public String getBusinessCity() {
        return businessCity;
    }

    public String getBusinessState() {
        return businessState;
    }

    public String getBusinessPostalCode() {
        return businessPostalCode;
    }

    public String getBusinessCountry() {
        return businessCountry;
    }

    public String getHomeStreet() {
        return homeStreet;
    }

    public String getHomeStreet2() {
        return homeStreet2;
    }

    public String getHomeStreet3() {
        return homeStreet3;
    }

    public String getHomeCity() {
        return homeCity;
    }

    public String getHomeState() {
        return homeState;
    }

    public String getHomePostalCode() {
        return homePostalCode;
    }

    public String getHomeCountry() {
        return homeCountry;
    }

    public String getOtherStreet() {
        return otherStreet;
    }

    public String getOtherStreet2() {
        return otherStreet2;
    }

    public String getOtherStreet3() {
        return otherStreet3;
    }

    public String getOtherCity() {
        return otherCity;
    }

    public String getOtherState() {
        return otherState;
    }

    public String getOtherPostalCode() {
        return otherPostalCode;
    }

    public String getOtherCountry() {
        return otherCountry;
    }

    public String getCompany() {
        return company;
    }

    public String getDepartment() {
        return department;
    }

    public String getJobTitle() {
        return jobTitle;
    }

    public String getAssistantPhone() {
        return assistantPhone;
    }

    public String getBusinessFax() {
        return businessFax;
    }

    public String getBusinessPhone() {
        return businessPhone;
    }

    public String getBusinessPhone2() {
        return businessPhone2;
    }

    public String getCallBack() {
        return callback;
    }

    public String getCarPhone() {
        return carPhone;
    }

    public String getCompanyMainPhone() {
        return companyMainPhone;
    }

    public String getHomeFax() {
        return homeFax;
    }

    public String getHomePhone() {
        return homePhone;
    }

    public String getHomePhone2() {
        return homePhone2;
    }

    public String getISDN() {
        return isdn;
    }

    public String getMobilePhone() {
        return mobilePhone;
    }

    public String getOtherFax() {
        return otherFax;
    }

    public String getOtherPhone() {
        return otherPhone;
    }

    public String getPager() {
        return pager;
    }

    public String getPrimaryPhone() {
        return primaryPhone;
    }

    public String getRadioPhone() {
        return radioPhone;
    }

    public String getTTYTTDPhone() {
        return TTYTTDPhone;
    }

    public String getTelex() {
        return telex;
    }

    public String getAssistantName() {
        return assistantName;
    }

    public String getBirthday() {
        return birthday;
    }

    public String getManagerName() {
        return managerName;
    }

    public String getNotes() {
        return notes;
    }

    public String getOtherPOBox() {
        return otherPOBox;
    }

    public String getSpouse() {
        return spouse;
    }

    public String getWebPage() {
        return webPage;
    }

    public String getPersonalWebPage() {
        return personalWebPage;
    }

    public void setTitle(final String title) {
        this.title = title;
    }

    public void setFirstName(final String firstName) {
        this.firstName = firstName;
    }

    public void setMiddleName(final String middleName) {
        this.middleName = middleName;
    }

    public void setLastName(final String lastName) {
        this.lastName = lastName;
    }

    public void setSuffix(final String suffix) {
        this.suffix = suffix;
    }

    public void setEmail(final String email) {
        this.email = email;
    }

    public void setEmail2(final String email2) {
        this.email2 = email2;
    }

    public void setEmail3(final String email3) {
        this.email3 = email3;
    }

    public void setBusinessStreet(final String businessStreet) {
        this.businessStreet = businessStreet;
    }

    public void setBusinessStreet2(final String businessStreet2) {
        this.businessStreet2 = businessStreet2;
    }

    public void setBusinessStreet3(final String businessStreet3) {
        this.businessStreet3 = businessStreet3;
    }

    public void setBusinessCity(final String businessCity) {
        this.businessCity = businessCity;
    }

    public void setBusinessState(final String businessState) {
        this.businessState = businessState;
    }

    public void setBusinessPostalCode(final String businessPostalCode) {
        this.businessPostalCode = businessPostalCode;
    }

    public void setBusinessCountry(final String businessCountry) {
        this.businessCountry = businessCountry;
    }

    public void setHomeStreet(final String homeStreet) {
        this.homeStreet = homeStreet;
    }

    public void setHomeStreet2(final String homeStreet2) {
        this.homeStreet2 = homeStreet2;
    }

    public void setHomeStreet3(final String homeStreet3) {
        this.homeStreet3 = homeStreet3;
    }

    public void setHomeCity(final String homeCity) {
        this.homeCity = homeCity;
    }

    public void setHomeState(final String homeState) {
        this.homeState = homeState;
    }

    public void setHomePostalCode(final String homePostalCode) {
        this.homePostalCode = homePostalCode;
    }

    public void setHomeCountry(final String homeCountry) {
        this.homeCountry = homeCountry;
    }

    public void setOtherStreet(final String otherStreet) {
        this.otherStreet = otherStreet;
    }

    public void setOtherStreet2(final String otherStreet2) {
        this.otherStreet2 = otherStreet2;
    }

    public void setOtherStreet3(final String otherStreet3) {
        this.otherStreet3 = otherStreet3;
    }

    public void setOtherCity(final String otherCity) {
        this.otherCity = otherCity;
    }

    public void setOtherState(final String otherState) {
        this.otherState = otherState;
    }

    public void setOtherPostalCode(final String otherPostalCode) {
        this.otherPostalCode = otherPostalCode;
    }

    public void setOtherCountry(final String otherCountry) {
        this.otherCountry = otherCountry;
    }

    public void setCompany(final String company) {
        this.company = company;
    }

    public void setDepartment(final String department) {
        this.department = department;
    }

    public void setJobTitle(final String jobTitle) {
        this.jobTitle = jobTitle;
    }

    public void setAssistantPhone(final String assistantPhone) {
        this.assistantPhone = assistantPhone;
    }

    public void setBusinessFax(final String businessFax) {
        this.businessFax = businessFax;
    }

    public void setBusinessPhone(final String businessPhone) {
        this.businessPhone = businessPhone;
    }

    public void setBusinessPhone2(final String businessPhone2) {
        this.businessPhone2 = businessPhone2;
    }

    public void setCallback(final String callback) {
        this.callback = callback;
    }

    public void setCarPhone(final String carPhone) {
        this.carPhone = carPhone;
    }

    public void setCompanyMainPhone(final String companyMainPhone) {
        this.companyMainPhone = companyMainPhone;
    }

    public void setHomeFax(final String homeFax) {
        this.homeFax = homeFax;
    }

    public void setHomePhone(final String homePhone) {
        this.homePhone = homePhone;
    }

    public void setHomePhone2(final String homePhone2) {
        this.homePhone2 = homePhone2;
    }

    public void setIsdn(final String isdn) {
        this.isdn = isdn;
    }

    public void setMobilePhone(final String mobilePhone) {
        this.mobilePhone = mobilePhone;
    }

    public void setOtherFax(final String otherFax) {
        this.otherFax = otherFax;
    }

    public void setOtherPhone(final String otherPhone) {
        this.otherPhone = otherPhone;
    }

    public void setPager(final String pager) {
        this.pager = pager;
    }

    public void setPrimaryPhone(final String primaryPhone) {
        this.primaryPhone = primaryPhone;
    }

    public void setRadioPhone(final String radioPhone) {
        this.radioPhone = radioPhone;
    }

    public void setTTYTTDPhone(final String TTYTTDPhone) {
        this.TTYTTDPhone = TTYTTDPhone;
    }

    public void setTelex(final String telex) {
        this.telex = telex;
    }

    public void setAssistantName(final String assistantName) {
        this.assistantName = assistantName;
    }

    public void setBirthday(final String birthday) {
        this.birthday = birthday;
    }

    public void setManagerName(final String managerName) {
        this.managerName = managerName;
    }

    public void setNotes(final String notes) {
        this.notes = notes;
    }

    public void setOtherPOBox(final String otherPOBox) {
        this.otherPOBox = otherPOBox;
    }

    public void setSpouse(final String spouse) {
        this.spouse = spouse;
    }

    public void setWebPage(final String webPage) {
        this.webPage = webPage;
    }

    public void setPersonalWebPage(final String personalWebPage) {
        this.personalWebPage = personalWebPage;
    }

}

This, in my mind, is a poor construction, but it is entirely possible and that's why I don't run into any issues compiling. Of course, because it's such an unusual construction, Ant may be having trouble trying to access it.

Note that ExcelFile.Java contains the non-public class ReadingObjects, which contains the main method. My theory is that, because ExcelFile.java isn't necessarily THE class that contains the main method, I'm running into issues

Let me know what you guys think. I'm willing to give things a shot.

Many thanks in advance!

-Justian

EDIT: Here is my build file:

<?xml version="1.0" ?>

<project name="ServerJar" default="dist" basedir=".">
    <description>
        Builds client files into .jar
    </description>
    <!-- [build variables] -->
    <property name="src" location="src" />
    <property name="build" location="build" />
    <property name="dist" location="dist" />
    <property name="lib" location="lib" />
    <!-- [path to packages] -->
    <path id="master-classpath">
        <fileset dir="${lib}">
            <include name="*.jar"/>
        </fileset>
    </path>


    <target name="init">
        <!-- makes time stamp to be used in jar name -->
        <tstamp />
        <!-- creates build directory structure -->
        <mkdir dir="${build}" />
    </target>

    <target name="compile" depends="init" description="Compiles the source">
        <!-- compiles the java code from ${src} into ${build} -->
        <!-- <javac srcdir="${src}" destdir="${build}" /> -->
        <javac destdir= "${build}">
            <src path="${src}"/>
            <classpath refid="master-classpath"/>
        </javac>
    </target>

    <target name="dist" depends="compile" description="Generates distributable">
    <!-- creates the distribution directory -->
        <mkdir dir="${dist}/lib" />

        <!-- puts everything in ${build} into the jar file -->
        <jar jarfile="${dist}/lib/CC-${DSTAMP}.jar" basedir="${build}">
            <manifest>
                <attribute name="Main-Class" value="jab.jm.main.ExcelFile" />
            </manifest>
        </jar>

        <!-- makes a jar file for quick test execution -->
        <jar jarfile="${dist}/lib/CC.jar" basedir="${build}">
            <manifest>
                <attribute name="Main-Class" value="jab.jm.main.ExcelFile" />
            </manifest>
        </jar>
    </target>

    <target name="clean" description="Cleans up the extra build files">
        <!-- deletes the ${build} and ${dist} directories -->
        <delete dir="${build}" />
        <delete dir="${dist}" />
    </target>
</project>

EDIT: No Luck on anything. Maybe we can look into reorganizing my one file into two?

I'm a little nervous about that because I don't know what kind of format SuperCSV requires.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

水中月 2024-09-14 07:52:41

确保您的清单文件中有以下条目:

Main-Class: com.yourcompany.ReadingObjects

之后,您将需要像这样运行您的程序:

$ java -jar nameofyourjar.jar

其他可能性包括像这样运行您的程序(不需要更改清单):

$ java -cp nameofyourjar.jar com.yourcompany.ReadingObjects

问候。

Make sure you have the following entry in your Manifest file:

Main-Class: com.yourcompany.ReadingObjects

After that, you will need to run you program like this:

$ java -jar nameofyourjar.jar

Other possibility includes running your program like this (with no need of Manifest change):

$ java -cp nameofyourjar.jar com.yourcompany.ReadingObjects

Regards.

阿楠 2024-09-14 07:52:41

使用 -jar 参数时,-cp(和 -classpath)参数将被忽略。您需要在 JAR 的 MANIFEST.MF 文件的 Class-Path 属性中指定它。

我的 ant 有点生疏,但它类似于这些行:

<attribute name="Class-Path" value="${dist.classpath}"/>

更新根据您的评论,您想知道如何直接使用 Eclipse 执行此操作,而不是与 Ant 麻烦。首先,您需要使用 Ctrl+F11 运行建议的 main() 方法,然后右键单击项目,选择“Export >”可运行的 JAR 文件(注意“可运行”部分,这很重要!)。然后,在向导中,您必须从列表中选择相同的启动配置(如果需要,请选择库处理),然后单击完成。这样,Eclipse 在生成 MANIFEST 文件时会自动考虑构建路径详细信息。

The -cp (and -classpath) arguments are ignored when using -jar argument. You need to specify it in the Class-Path attribute of JAR's MANIFEST.MF file.

My ant is a bit rusty, but it's something like those lines:

<attribute name="Class-Path" value="${dist.classpath}"/>

Update as per your comments you'd like to know how to do this directly with Eclipse instead of hassling with Ant. First, you need to run the proposed main() method using Ctrl+F11 and then rightclick the project, choose Export > Runnable JAR file (note "Runnable" part, this is important!). Then, in the Wizard you have to choose the same Launch configuration from the list (and if necessary choose library handling) and then click Finish. This way Eclipse will take the buildpath details automagically into account when generating the MANIFEST file.

九局 2024-09-14 07:52:41

无论您如何构建,最终都会在 JAR 中得到 META-INF/MANIFEST.MF。该文件(提取它以查看其包含的内容)需要有一个 Main-Class 条目,以便 JAR 可执行(当然,这样 java 就可以知道从哪个类开始执行)。标记为主类的类可以具有任何可见性 - 我倾向于将它们公开 - 并且方法必须同时是publicstatic< /代码>。

现在来说说另一个重要的问题。您需要将所有依赖项打包到可执行 JAR 文件中,因为您不能将位于 JAR 外部的内容放在类路径中。 (您可以使用另一个类加载器和动态加载技巧,但这完全是不同程度的毛茸茸的事情。)当您开始涉足这类事情时,Maven 开始看起来不那么令人难以承受了……

However you are building, you will end up with a META-INF/MANIFEST.MF in your JAR. That file – extract it to see what it contains – needs to have a Main-Class entry in it for the JAR to be executable (so java can know what class to start executing from, of course). The class that is marked as a main class can have any visibility – I tend to prefer to make them public – and the method must be both public and static.

Now for the other, important gotcha. You need to package all your dependencies in your executable JAR file as you can't put things located outside the JAR on the classpath. (You could use another class-loader and dynamic loading tricks, but that's an entirely different level of hairiness.) It's when you start to get into this sort of thing that Maven starts to look a little less overwhelming…

墨离汐 2024-09-14 07:52:41

您的 main 方法实际上位于 ReadingObjects 类中,并且该类也需要是 public
清单行应该是:

Main-Class: package jab.jm.main.ReadingObjects

这里有详细的说明和一个工作 ANT 文件来完成您想要做的事情。
构建一个可执行的.jar文件

再次研究你的代码后,我认为源文件应该名为ReadingObjects.javaReadingObjects类应该是public一切都会如你所愿。

your main method is actually on the ReadingObjects class, and that class needs to be public as well.
the manifest line should be:

Main-Class: package jab.jm.main.ReadingObjects

Here are detailed instructions and a working ANT file to do just what you are trying to do.
Build an Executable .jar file

After studying your code again, I think the source file should be called ReadingObjects.java, ReadingObjects Class should be public and everything will work as you want it.

你是我的挚爱i 2024-09-14 07:52:41

您还可以在 eclipse 中创建一个可运行的 jar,而不是 Ant 构建,它会询问您哪个文件保存了 main,它通常会找到正确的文件。如果我没记错的话,您应该选择将内容打包到 .jar 文件中。

You could also create a runnable jar in eclipse rather than an Ant build, it will ask you which file holds the main, it usually finds the correct one. You should then select, if I remember correctly, package contents into .jar file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文