我正在创建一个可以重新启动调用它的方法的类的库。它只需要该类来构建命令。这是我到目前为止所做的:
public static void restart(Class a) {
final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
try {
File currentJar = new File(a.class.getProtectionDomain().getCodeSource().getLocation().toURI());
/* is it a jar file? */
if(!currentJar.getName().endsWith(".jar")) {
return;
}
/* Build command: java -jar application.jar */
final ArrayList<String> command = new ArrayList<>(5);
command.add(javaBin);
command.add("-jar");
command.add(currentJar.getPath());
final ProcessBuilder builder = new ProcessBuilder(command);
builder.start();
System.exit(0);
} catch (URISyntaxException | IOException ex) {
Logger.getLogger(a.class.getName()).log(Level.SEVERE, null, ex);
}
}
问题是变量'a'未被识别为参数。有人可以帮忙吗?
答案 0 :(得分:2)
见下面的代码片段
public class Test {
public static void main(String[] args) {
Test test = new Test();
check(test.getClass());
}
public static void check(Class<?> a){
System.out.println(a);
}
}