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);
    
    
  • 相关阅读:
    cocostudio 使用教程
    anrdroid AVD启动不起来的问题。Waiting for HOME ('android.process.acore') to be launched
    Android SDK无法更新的问题解决办法
    Code(容斥,好题)
    莫比乌斯反演(转)
    随笔--新建查询
    11427
    uva11722
    uva11021
    How many integers can you find(容斥+dfs容斥)
  • 原文地址:https://www.cnblogs.com/byso/p/8879246.html
Copyright © 2011-2022 走看看