Skip to content

Commit 82af616

Browse files
pjungwirbpkroth
andauthored
Fix mvn exec:java ClassNotFoundException (#548)
This was reported by #493. Running benchmarks without packaging first fails like so: ``` mvn clean compile exec:java -P postgres -Dexec.args="-b tpcc -c config/postgres/sample_tpcc_config.xml --create=true --load=true --execute=true" java.lang.RuntimeException: Failed to retrieve class for com.oltpbenchmark.benchmarks.tpcc.TPCCBenchmark at com.oltpbenchmark.util.ClassUtil.getClass (ClassUtil.java:200) at com.oltpbenchmark.util.ClassUtil.getClass (ClassUtil.java:187) at com.oltpbenchmark.util.ClassUtil.newInstance (ClassUtil.java:112) at com.oltpbenchmark.DBWorkload.main (DBWorkload.java:165) at org.codehaus.mojo.exec.ExecJavaMojo.doMain (ExecJavaMojo.java:385) at org.codehaus.mojo.exec.ExecJavaMojo.doExec (ExecJavaMojo.java:374) at org.codehaus.mojo.exec.ExecJavaMojo.lambda$execute$0 (ExecJavaMojo.java:296) at java.lang.Thread.run (Thread.java:1583) Caused by: java.lang.ClassNotFoundException: com.oltpbenchmark.benchmarks.tpcc.TPCCBenchmark at jdk.internal.loader.BuiltinClassLoader.loadClass (BuiltinClassLoader.java:641) at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass (ClassLoaders.java:188) at java.lang.ClassLoader.loadClass (ClassLoader.java:526) at java.lang.Class.forName0 (Native Method) at java.lang.Class.forName (Class.java:534) at java.lang.Class.forName (Class.java:513) at org.apache.commons.lang3.ClassUtils.getClass (ClassUtils.java:532) at org.apache.commons.lang3.ClassUtils.getClass (ClassUtils.java:514) at com.oltpbenchmark.util.ClassUtil.getClass (ClassUtil.java:198) at com.oltpbenchmark.util.ClassUtil.getClass (ClassUtil.java:187) at com.oltpbenchmark.util.ClassUtil.newInstance (ClassUtil.java:112) at com.oltpbenchmark.DBWorkload.main (DBWorkload.java:165) at org.codehaus.mojo.exec.ExecJavaMojo.doMain (ExecJavaMojo.java:385) at org.codehaus.mojo.exec.ExecJavaMojo.doExec (ExecJavaMojo.java:374) at org.codehaus.mojo.exec.ExecJavaMojo.lambda$execute$0 (ExecJavaMojo.java:296) at java.lang.Thread.run (Thread.java:1583) ``` The bug was introduced by 611f3d4. I believe we should be using `Thread.getCurrentThread().getContextClassLoader()`, not `ClassLoader.getSystemClassLoader()`. --------- Co-authored-by: Brian Kroth <[email protected]> Co-authored-by: Brian Kroth <[email protected]>
1 parent 51ae02f commit 82af616

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

.github/workflows/maven.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ jobs:
6161
- name: Compile with Maven
6262
run: mvn -B compile test-compile --file pom.xml
6363

64+
- name: Test exec plugin
65+
run: |
66+
mvn exec:java -P sqlite -Dexec.args="-b noop -c config/sqlite/sample_noop_config.xml --create=true --load=true --execute=true"
67+
6468
- name: Test with Maven
6569
run: mvn -B test --file pom.xml
6670

src/main/java/com/oltpbenchmark/api/BenchmarkModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ public BenchmarkModule(WorkloadConfiguration workConf) {
6262
this.workConf = workConf;
6363
this.dialects = new StatementDialects(workConf);
6464
// setClassLoader();
65-
this.classLoader = ClassLoader.getSystemClassLoader();
65+
this.classLoader = Thread.currentThread().getContextClassLoader();
6666
}
6767

6868
/**
6969
* Instantiates the classLoader variable, needs to be overwritten if benchmark uses a custom
7070
* implementation.
7171
*/
7272
protected void setClassLoader() {
73-
this.classLoader = ClassLoader.getSystemClassLoader();
73+
this.classLoader = Thread.currentThread().getContextClassLoader();
7474
}
7575

7676
// --------------------------------------------------------------------------

src/main/java/com/oltpbenchmark/util/ClassUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public static <T> Constructor<T> getConstructor(Class<T> target_class, Class<?>.
184184
* @return
185185
*/
186186
public static Class<?> getClass(String class_name) {
187-
return getClass(ClassLoader.getSystemClassLoader(), class_name);
187+
return getClass(Thread.currentThread().getContextClassLoader(), class_name);
188188
}
189189

190190
/**

0 commit comments

Comments
 (0)