Tout d'abord, merci pour ta réponse extrêmement rapide.
L'erreur exacte est la suivante:
java.lang.NoClassDefFoundError: Could not initialize class com.sap.mw.jco.JCO
Stat_Prix_SPR.GetStat_Prix_SPR(Stat_Prix_SPR.java:40)
Stat_Prix_SPR_Application.doGet(Stat_Prix_SPR_Application.java:37)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Lorsque je n'utilise pas les servlets, il n'y a aucun problème.. Bon en lisant correctement je m'en rends compte d'où vient le problème..
Bon j'ai l'impression que si je mets ou non la librairie dans le répertoire lib, ça ne change rien au message d'erreur!!
Voici le code de mon applis
import java.math.*;
import com.sap.mw.jco.*;
/**
* Class to get Status and Prices for SPR.
*
* @author Vladimir, Luca
* @version 1.00 21/september/2007
*/
class Stat_Prix_SPR {
// Declare the instance variables for the IMPORT parameters of the function Z_STAT_PRIX.
public String I_MATNR;
public BigDecimal I_GAMNG;
public String I_KUNNR;
public String I_KONWA;
// Declare the instance variables for the EXPORT parameters of the function Z_STAT_PRIX.
public String I_STATUT;
public BigDecimal I_KBETR;
public String I_CODE_RET;
// Method to call the SAP function module through JCO.
public void GetStat_Prix_SPR() {
// The JCO is initialized and the program can use the different SAP objects
try {
// Get the properties for the JCO connection.
//Properties mylogin_properties = new Properties();
//mylogin_properties.load(new FileInputStream("./login.properties"));
// Create a client connection to a dedicated SAP system.
//JCO.Client myclient = JCO.createClient(mylogin_properties);
JCO.Client myclient = JCO.createClient("mandant","user","passwd","langue","server_appli","sytem-_num");
// Create a new SAP repository for this client.
IRepository myrepository = JCO.createRepository("MYRepository", myclient);
// Open the connection to the SAP system.
myclient.connect();
// Load the function interface from the SAP repository into the JCO reposotory
IFunctionTemplate myftemplateA = myrepository.getFunctionTemplate("Z_STAT_PRIX");
// The function interfaces has been successfully loaded
if (myftemplateA != null) {
// Create a function Z_STAT_PRIX from the template.
JCO.Function myfunctionA = myftemplateA.getFunction();
// Set the IMPORT parameters of the function Z_STAT_PRIX from the object variables.
JCO.Field myfieldI1 = myfunctionA.getImportParameterList().getField("I_MATNR");
myfieldI1.setValue(I_MATNR);
JCO.Field myfieldI2 = myfunctionA.getImportParameterList().getField("I_GAMNG");
myfieldI2.setValue(I_GAMNG);
JCO.Field myfieldI3 = myfunctionA.getImportParameterList().getField("I_KUNNR");
myfieldI3.setValue(I_KUNNR);
JCO.Field myfieldI4 = myfunctionA.getImportParameterList().getField("I_KONWA");
myfieldI4.setValue(I_KONWA);
// We can call the SAP function module Z_STAT_PRIX.
myclient.execute(myfunctionA);
// Get the EXPORT parameters of the function Z_STAT_PRIX into the object variables.
JCO.Field myfieldE1 = myfunctionA.getExportParameterList().getField("I_STATUT");
I_STATUT = myfieldE1.getString();
JCO.Field myfieldE2 = myfunctionA.getExportParameterList().getField("I_KBETR");
I_KBETR = myfieldE2.getBigDecimal();
JCO.Field myfieldE3 = myfunctionA.getExportParameterList().getField("I_CODE_RET");
I_CODE_RET = myfieldE3.getString();
}
else {
System.out.println("The function Z_STAT_PRIX cannot be loaded from the SAP system.");
}
// Close the SAP connection and free the JCO client.
myclient.disconnect();
myclient = null;
}
catch (Exception ex) {
System.out.println("Caught an exception: \n" + ex);
}
}
}
Ma fonction est effectivement un new FileInputStream("./login.properties");
Je me suis pas bien exprimé.
Je suis pas exactement novice en programmation. 4 ans d'expériences(7 avec mes études) et j'ai fait mes études en C++. Je ne suis pas surpris de la syntaxe de java et du moment que je reste dans du java classique je n'ai aucun problème. Mais c'est évident que je nage complètement(car je débute) avec Tomcat et les servlets.. Je suis 100% d'accord avec ta remarque. C'est ambitieux de ma part de vouloir allez si vite..
Partager