[英]Netbeans: How to use special project parameters in run command line?
I am trying to run a project that requires a specific file for proper execution. 我正在尝试运行一个需要特定文件才能正确执行的项目。 So far I have hard-coded the path to that file in the Run configuration's command line, but I would like to use a special project variable for that, that points to the actual directory the project is in. 到目前为止,我已经在运行配置的命令行中硬编码了该文件的路径,但是我想为此使用一个特殊的项目变量,该变量指向项目所在的实际目录。
Example (run command-line): 示例(运行命令行):
Now: /home/user/netbeansproject/myProject/myspecialfile.gz
Expected: ${project.dir}/myspecialfile.gz
Is this possible in Netbeans and if yes: how and where are those parameters documented? 在Netbeans中是否可行?如果可以,这些参数的记录方式和位置?
Try this! 尝试这个!
if (new File("myspecialfile.gz").exists()) {
System.out.println(new File("myspecialfile.gz").getAbsolutePath());
}
I would pass the path to main method with command line arguments when the application starts. 当应用程序启动时,我将使用命令行参数将路径传递给main方法。
if (args.length > 0) {
System.out.println(new File(args[0].trim()).getAbsolutePath());
} else {
throw new IllegalArgumentException("Configuration file needed to"
+ " run. Provide configuration file's path as argument.");
}
But maybe this solution is not what you're after. 但是也许这种解决方案不是您要追求的。
EDIT: 编辑:
Well if you define new "Run" configuration in your project properties and save it, then it is saved to ..NetBeansProjects/YOUR_PROJECT_NAME/nbproject/configs/your_configuration_name.properties 好吧,如果您在项目属性中定义新的“运行”配置并将其保存,那么它将保存到..NetBeansProjects / YOUR_PROJECT_NAME / nbproject / configs / your_configuration_name.properties
In that file you can define your commandline arguments like this: application.args="/somepath/NetBeansProjects/SomeProjectName/myspecialfile.gz" 在该文件中,您可以这样定义命令行参数:application.args =“ / somepath / NetBeansProjects / SomeProjectName / myspecialfile.gz”
I don't believe you can add ${somedir} reference to it. 我不相信您可以添加$ {somedir}引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.