unable to create jar when adding the package decla

2019-06-11 13:21发布

I received a very simple class with some folders that compiles like this without problems:

javac -classpath /home/DigestJavaLinux/classes DigestClass.java

In the classes folder i have one .class file called OasisEMSecImp.class

How ever I need to import the class and use its method in another project, the method generates a digest string for the bank to check a transaction, and receives the total and other parameters.

If I add

package digestclass;

to the begining of the class it does not work, i get the error:

digestclass/DigestClass.java:136: cannot find symbol
symbol  : class OasisEMSecImp
location: class DigestClass
        OasisEMSecImp digest= new OasisEMSecImp();
        ^
digestclass/DigestClass.java:136: cannot find symbol
symbol  : class OasisEMSecImp
location: class DigestClass
        OasisEMSecImp digest= new OasisEMSecImp();
                                  ^
2 errors

UPDATE: This is the file. It compiles without the package declaration:

package digestclass;

import java.*;

class DigestClass {
    private String varMerchant;
    private String varStore;                    // Store ID
    private String varTerm;             // Term ID
    private String varTotal;            // Monto de Transaccion
    private String varCurrency;             // Codigo de Moneda
    private String varOrder_id;         // Order Id
    private String varDigest;                       // Valor de Digest


    public DigestClass(String varMerchant, String varStore, String varTerm,
            String varTotal, String varCurrency, String varOrder_id,
            String varDigest) {
        super();
        this.varMerchant = varMerchant;
        this.varStore = varStore;
        this.varTerm = varTerm;
        this.varTotal = varTotal;
        this.varCurrency = varCurrency;
        this.varOrder_id = varOrder_id;
        this.varDigest = varDigest;
    }

    public String generateDigest(){
        OasisEMSecImp digest= new OasisEMSecImp();
        varDigest = digest.getDigest(this.varTotal,this.varOrder_id,this.varMerchant,this.varStore,this.varTerm,this.varCurrency);
        return varDigest;
    }

}

Why ? how to fix this ? Thank you very much for your time.

1条回答
Luminary・发光体
2楼-- · 2019-06-11 13:45

This is what i understand was the cause of the problem and what i did to go around it.

Like John Skeet pointed out, the class i was trying to use

OasisEMSecImp

Was compiled originally in the default package, which means that when it was compiled, the declaration

package example.package.OasisEMSecImp

At the beginning of the class was not used. As a consequence it can not be called from a class that does belongs to a package, and cant be integrated to my current project, which is pretty complex and uses packages declarations in every class.

The workaround was, i created a new and very simple application which works through command line and can be called from my application through exec, for example:

Process process = Runtime.getRuntime().exec("java " +
                                                    "-Djava.library.path=/home/ernesto/DigestJavaLinux/lib " +
                                                    "-classpath /home/ernesto/workspace/digestUserTest/bin:/home/ernesto/workspace/digestUserTest/lib/digestgenerator.jar: " +
                                                    "ARGUMENTS");

I understood this was the situation thanks to this link

I hope this helps someone. And thank you for your help.

查看更多
登录 后发表回答