从jar文件中调用所需的方法

时间:2015-04-16 12:27:51

标签: java jar

下面是我的java文件,我输出的是一个单独的jar文件,jar的名称是“Softassert”

package com.annuity_payer;

import java.util.Arrays;
import java.util.Map;

import org.testng.Assert;
import org.testng.Reporter;

import com.thoughtworks.selenium.SeleneseTestBase;

public class Softassert extends SeleneseTestBase {
    private StringBuffer verificationErrors;
    private StringBuffer verificationSuccess;

    public Softassert() {
        verificationErrors = new StringBuffer();
        verificationSuccess = new StringBuffer();
    }


    public void verifyEquals(String actual, String expected, String msg) {
        try {
            Assert.assertEquals(actual, expected, msg);
            verificationSuccess.append(msg + ":" + " " + "Actual Result:" + " "
                    + actual + " " + "Expected Result:" + " " + expected
                    + " - Condition PASSED" + "\n");

        } catch (AssertionError e) {
            verificationErrors.append(e + "-Condition FAILED" + "\n");          
        }
    }
}

所以我正在创建一个新项目,并使用构建路径映射jar文件以从jar文件中检索方法

下面是代码

   import com.annuity_payer.Softassert.*;

    public class testJar {
        Softassert prabu = new Softassert();
        prabu.verifyEquals("test","test","verification");

从上面我创建一个对象名称“prabu”,然后尝试调用欲望方法(即verifyEquals方法)
当我尝试相同时它显示错误“令牌上的语法错误”请澄清/帮助如何从我的jar文件中调用该方法

1 个答案:

答案 0 :(得分:0)

如果您只想导入" Softassert",请使用...

,您不需要导入中的星号
import com.annuity_payer.Softassert;

如果你想要annuity_payer包中的所有类,你可以使用

import com.annuity_payer.*;

您可能会对"导入静态"感到困惑。语句