Skip to content

Commit a717d03

Browse files
committed
JavaSourceCompiler#compile增加自定义options重载
1 parent ccc316e commit a717d03

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* 【core 】 build(pom): 添加 Automatic-Module-Name属性(pr#2926@Github)
1111
* 【core 】 根据JDK-8080225修改了部分新建文件输入流和文件输出流的创建方式(pr#2930@Github)
1212
* 【http 】 HttpRequest#body增加支持Resource重载(issue#2901@Github)
13+
* 【core 】 JavaSourceCompiler#compile增加自定义options重载(issue#I6IVZK@Gitee)
1314

1415
### 🐞Bug修复
1516
* 【db 】 修复识别JDBC驱动时重复问题(pr#940@Gitee)

hutool-core/src/main/java/cn/hutool/core/compiler/JavaSourceCompiler.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ public JavaSourceCompiler addLibrary(File... files) {
168168
* @return 类加载器
169169
*/
170170
public ClassLoader compile() {
171+
return compile(null);
172+
}
173+
174+
/**
175+
* 编译所有文件并返回类加载器
176+
*
177+
* @param options 编译参数
178+
* @return 类加载器
179+
*/
180+
public ClassLoader compile(List<String> options) {
171181
// 获得classPath
172182
final List<File> classPath = getClassPath();
173183
final URL[] urLs = URLUtil.getURLs(classPath.toArray(new File[0]));
@@ -181,7 +191,9 @@ public ClassLoader compile() {
181191
final JavaClassFileManager javaFileManager = new JavaClassFileManager(ucl, CompilerUtil.getFileManager());
182192

183193
// classpath
184-
final List<String> options = new ArrayList<>();
194+
if (null == options) {
195+
options = new ArrayList<>();
196+
}
185197
if (false == classPath.isEmpty()) {
186198
final List<String> cp = CollUtil.map(classPath, File::getAbsolutePath, true);
187199
options.add("-cp");

0 commit comments

Comments
 (0)