问题描述
我收到了一个非常简单的类,其中有一些文件夹可以像这样编译没有问题:
I received a very simple class with some folders that compiles like this without problems:
javac -classpath /home/DigestJavaLinux/classes DigestClass.java
在 classes 文件夹中,我有一个名为 OasisEMSecImp.class
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.
如果我添加
包摘要类;
在课程开始时它不起作用,我收到错误:
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.
推荐答案
这就是我所理解的问题的原因以及我为解决该问题所做的工作.
This is what i understand was the cause of the problem and what i did to go around it.
就像 John Skeet 指出的那样,我试图使用的类
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
包 example.package.OasisEMSecImp
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.
解决方法是,我创建了一个新的非常简单的应用程序,它通过命令行工作,可以通过 exec 从我的应用程序中调用,例如:
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 hope this helps someone. And thank you for your help.
这篇关于添加包声明时无法创建 jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!