zoukankan      html  css  js  c++  java
  • maven配置自动生成sql文件

    step 1 : 配置maven的策略

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>${exec.maven.plugin.version}</version>
        <executions>
            <execution>
                <phase>prepare-package</phase>
                <goals>
                    <goal>java</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <mainClass>com.test.SchemaGenerator</mainClass>
            <arguments>
                <argument>com.test.db.entity</argument>
                <argument>${project.basedir}/sql/</argument>
                <argument>test.sql</argument>
            </arguments>
        </configuration>
    </plugin>
    

    step 2 :实现策略操作:

    Configuration cfg;
    cfg = new Configuration();
    cfg.setProperty("hibernate.hbm2ddl.auto", "create");// 从包中得到所有相关class
    File directory = null;
    ClassLoader cld = Thread.currentThread().getContextClassLoader();
    URL resource = getResource(packageName, cld);
    directory = new File(resource.getFile());
    Class.forName(className)
    for clazz in classes
    cfg.addAnnotatedClass(clazz);
    cfg.setProperty("hibernate.dialect","org.hibernate.dialect.MySQLDialect");
    SchemaExport export = new SchemaExport(cfg);
    export.setDelimiter(":");
    export.setOutputFile(directory + fileName);
    export.setFormat(true);
    export.execute(true, false, false, false);
    
    
  • 相关阅读:
    再读《赤壁赋》念《滕王阁序》
    赤壁赋
    关于C语言中的位域
    Eliot
    cnblogs.com博客园简介
    springboot+thymeleaf 实现图片文件上传及回显
    绑定事件的方式
    无法获得 VMCI 驱动程序的版本: 句柄无效。
    Connection is read-only解决方式
    Java 线程的 5 种状态
  • 原文地址:https://www.cnblogs.com/byso/p/8879246.html
Copyright © 2011-2022 走看看