diff --git a/README.md b/README.md index fb077d51..815a3c68 100644 --- a/README.md +++ b/README.md @@ -23,27 +23,23 @@ mybatis-generator-gui是基于[mybatis generator](http://www.mybatis.org/generat cd mybatis-generator-gui mvn jfx:jar ### 启动本软件 -* 方法一: 下载的zip包 -解压zip包,如果安装好了JRE或者JDK 8,直接cd至软件目录运行 - - java -jar mybatis-generator-gui.jar - -* 方法二: 自助构建 +* 方法一: 自助构建 + mvn install:install-file -Dfile=./src/main/resources/connector/ojdbc14.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.3.0 -Dpackaging=jar -DgeneratePom=true cd target/jfx/app/ java -jar mybatis-generator-gui.jar -* 方法三: IDE中运行 +* 方法二: IDE中运行 -Eclipse or IntelliJ IDEA中启动, 找到MainUI类并运行就可以了 +Eclipse or IntelliJ IDEA中启动, 找到```com.zzg.mybatis.generator.MainUI```类并运行就可以了 #### Oracle用户请注意 由于Oracle的驱动在maven官方的repository中没有,Oracle的用户需要手动安装一下驱动,cd到项目目录下,执行: - mvn install:install-file -Dfile=./src/main/resources/connector/ojdbc14.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.3.0 -Dpackaging=jar -DgeneratePom=true + ### 文档 diff --git a/pom.xml b/pom.xml index 3672cdcc..fd400b0f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.zzg mybatis-generator-gui - 0.6 + 0.7.2 UTF-8 diff --git a/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java b/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java index 68a6d62d..a01ec176 100644 --- a/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java +++ b/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java @@ -12,6 +12,8 @@ import org.mybatis.generator.api.ShellCallback; import org.mybatis.generator.config.*; import org.mybatis.generator.internal.DefaultShellCallback; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.HashSet; @@ -26,6 +28,8 @@ */ public class MybatisGeneratorBridge { + private static final Logger _LOG = LoggerFactory.getLogger(MybatisGeneratorBridge.class); + private GeneratorConfig generatorConfig; private DatabaseConfig selectedDatabaseConfig; @@ -57,6 +61,7 @@ public void setDatabaseConfig(DatabaseConfig databaseConfig) { public void generate() throws Exception { Configuration config = new Configuration(); String connectorLibPath = ConfigHelper.findConnectorLibPath(selectedDatabaseConfig.getDbType()); + _LOG.info("connectorLibPath: {}", connectorLibPath); config.addClasspathEntry(connectorLibPath); Context context = new Context(ModelType.CONDITIONAL); config.addContext(context); diff --git a/src/main/java/com/zzg/mybatis/generator/model/DbType.java b/src/main/java/com/zzg/mybatis/generator/model/DbType.java index b3bab91d..d8d5dbec 100644 --- a/src/main/java/com/zzg/mybatis/generator/model/DbType.java +++ b/src/main/java/com/zzg/mybatis/generator/model/DbType.java @@ -5,9 +5,9 @@ */ public enum DbType { - MySQL("com.mysql.jdbc.Driver", "jdbc:mysql://%s:%s/%s?useUnicode=true&useSSL=false&characterEncoding=%s", "connector/mysql-connector-java-5.1.38.jar"), - Oracle("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@%s:%s:%s", "connector/ojdbc14.jar"), - PostgreSQL("org.postgresql.Driver", "jdbc:postgresql://%s:%s/%s", "connector/postgresql-9.4.1209.jar"); + MySQL("com.mysql.jdbc.Driver", "jdbc:mysql://%s:%s/%s?useUnicode=true&useSSL=false&characterEncoding=%s", "mysql-connector-java-5.1.38.jar"), + Oracle("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@%s:%s:%s", "ojdbc14.jar"), + PostgreSQL("org.postgresql.Driver", "jdbc:postgresql://%s:%s/%s", "postgresql-9.4.1209.jar"); private final String driverClass; private final String connectionUrlPattern; diff --git a/src/main/java/com/zzg/mybatis/generator/util/ConfigHelper.java b/src/main/java/com/zzg/mybatis/generator/util/ConfigHelper.java index d021db72..7f2cc524 100644 --- a/src/main/java/com/zzg/mybatis/generator/util/ConfigHelper.java +++ b/src/main/java/com/zzg/mybatis/generator/util/ConfigHelper.java @@ -4,6 +4,7 @@ import com.zzg.mybatis.generator.model.DatabaseConfig; import com.zzg.mybatis.generator.model.DbType; import com.zzg.mybatis.generator.model.GeneratorConfig; +import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -200,17 +201,18 @@ public static int deleteGeneratorConfig(String name) throws Exception { public static String findConnectorLibPath(String dbType) { DbType type = DbType.valueOf(dbType); String connectorJarFileName = type.getConnectorJarFile(); - URL resource = Thread.currentThread().getContextClassLoader().getResource(connectorJarFileName); + URL resource = Thread.currentThread().getContextClassLoader().getResource("logback.xml"); + _LOG.info("jar resource: {}", resource); if (resource != null) { - try { - return resource.toURI().getRawPath(); - } catch (URISyntaxException e) { - // ignore + try { + File file = new File(resource.toURI().getRawPath() + "/../lib/" + type.getConnectorJarFile()); + return file.getCanonicalPath(); + } catch (Exception e) { + throw new RuntimeException("找不到驱动文件,请联系开发者"); } } else { - throw new RuntimeException("connector can't find"); + throw new RuntimeException("lib can't find"); } - return null; } diff --git a/src/main/resources/connector/mysql-connector-java-5.1.38.jar b/src/main/resources/lib/mysql-connector-java-5.1.38.jar similarity index 100% rename from src/main/resources/connector/mysql-connector-java-5.1.38.jar rename to src/main/resources/lib/mysql-connector-java-5.1.38.jar diff --git a/src/main/resources/connector/ojdbc14.jar b/src/main/resources/lib/ojdbc14.jar similarity index 100% rename from src/main/resources/connector/ojdbc14.jar rename to src/main/resources/lib/ojdbc14.jar diff --git a/src/main/resources/connector/postgresql-9.4.1209.jar b/src/main/resources/lib/postgresql-9.4.1209.jar similarity index 100% rename from src/main/resources/connector/postgresql-9.4.1209.jar rename to src/main/resources/lib/postgresql-9.4.1209.jar