在做了一些研究之后我问了这个问题.我确实遵循了这种错误给出的解决方案,但对我没有用.在下面的代码中出现错误的任何建议.我正在创建一个REST API但是当我请求url时它给了我405错误.Below是请求的URI.
http://localhost:8080/Project/services/start/version
Run Code Online (Sandbox Code Playgroud)
以下是代码段.
@Path("/start")
public class StartService {
@GET
@Path("/version")
@Produces({"text/plain","application/xml","application/json"})
public String getVersion() {
String ver="";
try{
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("C:\\server\\dgr -v" );
BufferedReader stdInput = new BufferedReader(new InputStreamReader
(pr.getInputStream()));
BufferedReader input = new BufferedReader(stdInput);
// String ver ="";
StringBuffer verOutput = new StringBuffer();
while((ver = input.readLine()) != null){
verOutput.append(ver + "\n");
System.out.println(ver);
}
}catch (Throwable t)
{
t.printStackTrace();
}
finally {
}
return ver; }
}
Run Code Online (Sandbox Code Playgroud)
web.xml中:
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"> …Run Code Online (Sandbox Code Playgroud) 我在做了大量的研究之后问了这个问题,并且在研究之后在我的代码中实现了这个问题,但我最终得到了FileNotFoundException.我在这里做的是我想要避免在我的java代码中使用硬编码所以创建一个名为的属性文件作为Constants.properties并在我的java代码中调用它.但它说它找不到文件.我的属性文件位于项目的src文件夹中.以下是代码段.有什么建议?
属性文件:
executable.run = C:\\server\\lrd.exe
incoming.file = C:\\file\\test.ic
executable.params1 = -z
executable.params2 = -a[+]
log.file = C:\\TESTFile\\test.txt
Run Code Online (Sandbox Code Playgroud)
Java代码:这是具有属性文件详细信息的类文件.
public class PropInfo {
static private PropInfo _instance = null;
public String executable = null;
public String filein = null;
public String params1 = null;
public String params2 = null;
public String log = null;
protected PropInfo(){
try{
InputStream file = new FileInputStream(new File("Constants.properties"));
Properties props = new Properties();
props.load(file);
executable = props.getProperty("executable.run");
filein = props.getProperty("incomin.file");
params1 = props.getProperty("executable.params1");
params2 = props.getProperty("executable.params2"); …Run Code Online (Sandbox Code Playgroud)