Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running MBG from Java with an XML Configuration File issue #1124

Open
yon173089350 opened this issue Dec 30, 2023 · 0 comments
Open

Running MBG from Java with an XML Configuration File issue #1124

yon173089350 opened this issue Dec 30, 2023 · 0 comments

Comments

@yon173089350
Copy link

Hi, Team,

I try to run MBG from Java with an XML Configuration, but no java file can be generated & no error infomation, would you help to check? thank you.

=========Java============
public class Table2Class {
public static void main(String[] args) {

    try {
        URL url = Thread.currentThread().getContextClassLoader().getResource("generatorConfig.xml");
        URI uri = Objects.requireNonNull(url).toURI();
        Path path = Paths.get(uri);
        String content = Files.readString(path);
        InputStream inputStream = new ByteArrayInputStream(content.getBytes());

        List<String> warnings = new ArrayList<>();
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(inputStream);

        DefaultShellCallback callback = new DefaultShellCallback(true);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    } catch (Exception ex) {
        System.out.printf(ExceptionUtils.findNestedThrowables(ex).toString());
    }
}

}
========generatorConfig.xml=========

    <jdbcConnection driverClass="org.postgresql.Driver"
                    connectionURL="jdbc:postgresql://127.0.0.1:5432/test"
                    userId=""
                    password=""/>

    <javaModelGenerator targetPackage="larkisland.db.model" targetProject="src/main/java"/>

    <sqlMapGenerator targetPackage="larkisland.db.mapper" targetProject="src/main/resources"/>

    <javaClientGenerator type="XMLMAPPER" targetPackage="larkisland.db.mapper" targetProject="src/main/java"/>

    <table tableName="test_job" schema="public"/>

</context>

============SQL=============
CREATE TABLE IF NOT EXISTS public.test_job
(
job_id character varying COLLATE pg_catalog."default" NOT NULL,
cron character varying COLLATE pg_catalog."default",
CONSTRAINT test_pkey PRIMARY KEY (job_id)
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.test_job
OWNER to test;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant