Java 如何获取eclipse包目录工作区路径
我试图以编程方式编写或更新包中的.java文件,但我没有得到正确的路径。大多数代码返回我保存eclipse软件的路径,但我需要工作区路径。以下代码,我正在使用Java 如何获取eclipse包目录工作区路径,java,eclipse,Java,Eclipse,我试图以编程方式编写或更新包中的.java文件,但我没有得到正确的路径。大多数代码返回我保存eclipse软件的路径,但我需要工作区路径。以下代码,我正在使用 URL location = InstallationStepsServlet.class.getProtectionDomain().getCodeSource().getLocation(); String directoryToCreateFile = location.getFile().replace(File
URL location = InstallationStepsServlet.class.getProtectionDomain().getCodeSource().getLocation();
String directoryToCreateFile = location.getFile().replace(FilesName.SERVLET_INSTALLATION_STEPS+".class", "");
out.println(directoryToCreateFile);
out.println("<br/>"+System.getProperty("user.dir")+"<br/>");
out.println(new File("CMS").getAbsolutePath());
File file = new File(".");
String currentDirectory = file.getAbsolutePath();
out.println("<br/>Current working directory : "+currentDirectory);
URL location=installationstepservlet.class.getProtectionDomain().getCodeSource().getLocation();
String directoryToCreateFile=location.getFile().replace(filename.SERVLET_安装_步骤+”.class“,”);
out.println(directoryToCreateFile);
out.println(“
”+System.getProperty(“user.dir”)+”
);
out.println(新文件(“CMS”).getAbsolutePath();
文件文件=新文件(“.”);
字符串currentDirectory=file.getAbsolutePath();
out.println(“
当前工作目录:“+currentDirectory”);
上面的代码都不适合我
要求
我的动机是以编程方式在SiteConfig.java中编写,这就是我试图获取目录路径的原因
同样的代码也适用于在线服务器吗?您希望实现什么。您稍后是否尝试重新编译SiteConfig?通常在部署应用程序时,它将位于WEB-INF/classes中。我将在SiteConfig文件中写入用户的数据库详细信息,我将在整个项目中使用该文件。如果在SiteConfig中写入任何内容,则必须重新编译。如果您编写一些详细信息,如用户名或类似的内容,请考虑将其存储在数据库或文件中,然后访问该文件或数据库