Ich versuche, alle meine URLs & Pfade in .properties-Datei zu setzen. Wenn ich sie also ändern würde, wäre es einfacher. Also hier ist mein path.properties (es ist in src \ main \ resources \ META-INF \ spring \ path.properties):Lesen von Pfaden in Datei .properties
path.clientIdentify=C:\\Palms\\client-identify-bin\\dll
path.clientEnroll=C:\\Palms\\client-enroll-bin\\dll
path.pvInfoIni=C://Palms//PV//PVInfo.ini
path.pvEnrollIni=C://Palms//PV//PVEnroll.ini
Und ich habe versucht, die Wege in meinem Controller zu nennen, so ist dies, was ich did:
@Controller
@RequestMapping("/call")
public class PalmsController {
@RequestMapping(value = "/palmsIdentify")
public ResponseEntity<String> palmusIdentify() throws IOException, InterruptedException {
Properties properties = new Properties();
try (InputStream is = new FileInputStream("classpath*:META-INF/spring/*.properties")) {
properties.load(is);
}
HttpHeaders headers = new HttpHeaders();
ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", "StartSample.bat");
builder.directory(new File("path.clientIdentify"));
Process process = builder.start();
BufferedReader r = new BufferedReader(new InputStreamReader(process.getInputStream()));
r.close();
process.waitFor();
Properties p = new Properties();
try {
p.load(new FileInputStream("path.pvInfoIni"));
String pvidNO1 = p.getProperty("PVIDNO");
String pvidNo2 = p.getProperty("PVIDNo");
String authentication = p.getProperty("Authentication");
// Convert to JSON
JSONObject jsonObject = new JSONObject();
jsonObject.put("pvId", pvidNO1);
jsonObject.put("PVIDNo", pvidNo2);
jsonObject.put("is_Authenticated", authentication);
return new ResponseEntity<String>(jsonObject.toString(),headers ,HttpStatus.OK);
}
catch (Exception e) {
return new ResponseEntity<String>("{\"ERROR\":" + e.getMessage() + "\"}", headers,
HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@RequestMapping(value = "/palmusEnroll")
public ResponseEntity<String> palmusEnroll() throws IOException, InterruptedException {
Properties properties = new Properties();
try (InputStream is = new FileInputStream("classpath*:META-INF/spring/*.properties")) {
properties.load(is);
}
HttpHeaders headers = new HttpHeaders();
ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", "StartSample.bat");
builder.directory(new File("path.clientEnroll"));
Process process = builder.start();
BufferedReader r = new BufferedReader(new InputStreamReader(process.getInputStream()));
r.close();
process.waitFor();
// PARSING
Properties p = new Properties();
try {
p.load(new FileInputStream("path.pvEnrollIni"));
String pvidNO1 = p.getProperty("PVIDNO");
String palmusId = p.getProperty("PALMUS_ID");
// Convert to JSON
JSONObject jsonObject = new JSONObject();
jsonObject.put("pvId", pvidNO1);
jsonObject.put("palmusId", palmusId);
return new ResponseEntity<String>(jsonObject.toString(),headers ,HttpStatus.OK);
}
catch (Exception e) {
return new ResponseEntity<String>("{\"ERROR\":" + e.getMessage() + "\"}", headers,
HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
Aber es scheint, als würde es nicht die Pfade aufrufen. Oder vielleicht mache ich es nicht richtig? Sorry Neuling hier, ich hoffe jemand kann mir helfen. Vielen Dank.
Funktionierte immer noch nicht Sir. –
Können Sie debuggen, wenn Ihr Code sogar die Eigenschaftendatei lädt? – kevto
Ich habe die Fehlerressource nicht gefunden. Daher wird die Eigenschaftendatei nicht geladen. Warum das? –