joelittlejohn / jsonschema2pojo

Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
http://www.jsonschema2pojo.org
Apache License 2.0
6.24k stars 1.66k forks source link

Within Java project can't find output file #1289

Closed zzhengyang closed 3 years ago

zzhengyang commented 3 years ago

When I run this demo

public static void main(String[] args) throws IOException {

    // BEGIN EXAMPLE

    JCodeModel codeModel = new JCodeModel();

    URL source = Example.class.getResource("/schema/required.json");

    GenerationConfig config = new DefaultGenerationConfig() {
        @Override
        public boolean isGenerateBuilders() { // set config option by overriding method
            return true;
        }
    };

    SchemaMapper mapper = new SchemaMapper(new RuleFactory(config, new Jackson2Annotator(config), new SchemaStore()), new SchemaGenerator());
    mapper.generate(codeModel, "ClassName", "com.youku.video.util", source);

    codeModel.build(Files.createTempDirectory("required").toFile());

    // END EXAMPLE

}

OUTPUT:

com/youku/video/util/Required.java

But I can't find the output file.

unkish commented 3 years ago

Hi

Have you looked in tmp dir ? Perhaps changing

    codeModel.build(Files.createTempDirectory("required").toFile());

to

      File tmpDir = Files.createTempDirectory("required").toFile();
      codeModel.build(tmpDir);
      System.out.println("Output generated to: " + tmpDir);

would help to get temporary directory that output was generated to