greenDAO schema generation with relative output path; failing with i/o not found

StackOverflow https://stackoverflow.com/questions/23115745

  •  04-07-2023
  •  | 
  •  

Frage

Following along with this tutorial, I've been able to create a working app module that compiles and runs, but fails if I pass a relative path to the generateAll method. It works fine if I specify an absolute path. My android studio project is composed of a few modules, structured like

project_root, with sub directories for each of it's modules

/daogenerator

/app

Each has it's own src directories, and I'm calling the generateAll like:

new DaoGenerator().generateAll(schema,
                "../app/src");

which results in an io error, indicating that the directory doesn't exist. I've modified the path to many reasonable alternatives, and confirmed that the paths exist on disk, but still getting the error. The absolute path works fine, so I'm trying to understand what I'm missing to get it working with a relative path. Thanks.

War es hilfreich?

Lösung

The outDir parameter is expected to be relative to the project directory.

For example, suppose your MyDaoGenerator class is in module1 under projectA and you want to generate the DAO classes into a separate module2 of the same project ...

projectA
    module1/
        src/main/java/com.my.package/MyDaoGenerator.java
    module2/
        src/main/java/      <-- target directory

... the outDir parameter would be module2/src/main/java.

Andere Tipps

In my case I had to change the package to this

 new DaoGenerator().generateAll(schema, "app/src/main/java");

from this

new DaoGenerator().generateAll(schema, "../app/src/main/java");

Perhaps you could check the run configurations.

If your dao generator code is in a class named M.java, you can edit the run configuration for it:

enter image description here

Then you should ensure that it is pointing to the right working directory:

enter image description here

Finally, we can generate the dao code:

public static void main(String[] args) throws Exception
{
    ...
    new DaoGenerator().generateAll(schema, "."); // direct to working directory
}

It worked for me. Hope it help.

Source: this tutorial

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top