0

i am trying to run my main class and to add additional property files into the classpath but it does not happen. I saw some solutions like link but they do not work for me. I also tried adding "-cp \path to property files" into Run configuration -> VM options but again without success.

Bozhidar Marinov
  • 116
  • 2
  • 15
  • Add the directory to the module dependency (https://www.jetbrains.com/help/idea/creating-and-managing-modules.html#working-with-module-dependencies) or place the files in the resource root. See https://www.jetbrains.com/help/idea/configuring-content-roots.html. – CrazyCoder Dec 03 '19 at 20:39
  • I do not want to make some code changes or to add new files/directories. I just want to run the main method and give -cp "$MY_PATH" – Bozhidar Marinov Dec 04 '19 at 07:24
  • 1
    IntelliJ IDEA doesn't support it, see https://youtrack.jetbrains.com/issue/IDEA-160167. – CrazyCoder Dec 04 '19 at 07:26
  • That is rediculous. Eclipse is free and has it from a very long time. Thank you – Bozhidar Marinov Dec 04 '19 at 07:34

1 Answers1

0

If I'm understanding you correctly, you'll have to create the file first if you don't want to read from the existing one, then write to it in something similar as below:

    try {
        File f = new File("path/to/propertyFile.properties");
        if (file.createNewFile()){
            // some debugging
            System.out.println("File is created!");
        }else{
            System.out.println("File already exists.");
        }
        // you have your file now, and you can perform manipulations to it
        OutputStream output = new FileOutputStream("path/to/propertyFile.properties")
        Properties prop = new Properties();

        prop.setProperty("key", "value");
        // save properties to project root folder
        prop.store(output, null);

    } catch (IOException io) {
        io.printStackTrace();
    }
Manish Karki
  • 473
  • 2
  • 11
  • No, i am running a main method which is usually called by bash script which add classpath, but now i am running through intellij and i want to add this classpath on starting the main class without code changes – Bozhidar Marinov Dec 04 '19 at 07:22