我按照一本关于使用Glassfish的javaEE的书写了以下三个java文件。
ClassValidator.java
import javax.jws.WebService;
@WebService
public class CardValidator {
public boolean validate(CreditCard creditCard){
Character lastDigit = creditCard.getNumber().charAt(creditCard.getNumber().length()-1);
if(Integer.parseInt(lastDigit.toString())%2 != 0){
return true;
}
else{
return false;
}
}
}
CreditCard.java
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class CreditCard {
private String number;
private String expiryDate;
private Integer controlNumber;
private String type;
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getExpiryDate() {
return expiryDate;
}
public void setExpiryDate(String expiryDate) {
this.expiryDate = expiryDate;
}
public Integer getControlNumber() {
return controlNumber;
}
public void setControlNumber(Integer controlNumber) {
this.controlNumber = controlNumber;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
Main.Java
public class Main {
public static void main(String[] args) {
CreditCard creditCard = new CreditCard();
creditCard.setNumber("12341234");
creditCard.setExpiryDate("10/10");
creditCard.setType("VISA");
creditCard.setControlNumber(1234);
CardValidator cardValidator = new CardValidatorService().getCardValidatorPort();
cardValidator.validate(creditCard);
}
}
我在调用callValidatorService构造函数的行中的Main.java中收到错误(CardValidatorService无法解析为某个类型)。如何克服这个错误?我应该做什么其他配置,成功运行?