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);
    
    
  • 相关阅读:
    Appsacn 定期自动化扫描
    安全扫描工具 AppScan
    安全扫描工具 Netsparker
    Appium环境搭建
    selenium元素定位大全
    浅谈 WebDriver如何应对不同浏览器
    自动化环境搭建
    三次握手四次挥手
    通俗讲解python__new__()方法
    第十三章、元类之控制类的调用过程
  • 原文地址:https://www.cnblogs.com/byso/p/8879246.html
Copyright © 2011-2022 走看看