Commit e1bf5266 authored by hewei's avatar hewei

动态编译输出目录移动到class目录下

parent 26afb426
......@@ -88,7 +88,7 @@ public class BatchInsertPluginTest {
@Test
public void testMethods() throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException, ClassNotFoundException, NoSuchMethodException {
List<String> warnings = new ArrayList<String>();
List<String> warnings = new ArrayList<>();
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(Resources.getResourceAsStream("scripts/BatchInsertPlugin/mybatis-generator.xml"));
......
......@@ -16,7 +16,6 @@
package com.itfsw.mybatis.generator.plugins.tools;
import org.junit.Assert;
import org.mybatis.generator.api.ShellCallback;
import org.mybatis.generator.exception.ShellException;
......@@ -25,9 +24,6 @@ import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
......@@ -74,20 +70,16 @@ public abstract class AbstractShellCallback implements ShellCallback {
//设置编译参数
ArrayList<String> ops = new ArrayList<>();
ops.add("-Xlint:unchecked");
// 设置输出目录
ops.add("-d");
ops.add(this.getClass().getClassLoader().getResource("").getPath());
//获取编译任务
JavaCompiler.CompilationTask task = compiler.getTask(null, manager, null, ops, null, it);
//执行编译任务
task.call();
try {
reloadProject(new URLClassLoader(new URL[]{new File(project).toURI().toURL()}));
} catch (MalformedURLException e) {
e.printStackTrace();
Assert.assertTrue(false);
}
} else {
reloadProject(this.getClass().getClassLoader());
}
reloadProject(this.getClass().getClassLoader());
}
public abstract void reloadProject(ClassLoader loader);
......
......@@ -22,6 +22,7 @@ import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.*;
import java.net.URL;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
......@@ -118,6 +119,12 @@ public class DBHelper {
*/
public static void cleanDao(){
delDir(new File("src/test/java/com/itfsw/mybatis/generator/plugins/dao"));
// 清理Dao class目录
URL daoClass = DBHelper.class.getClassLoader().getResource("com/itfsw/mybatis/generator/plugins/dao");
if (daoClass != null){
delDir(new File(daoClass.getPath()));
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment