我需要在运行时从jar文件中加载一些类,但每次尝试时,我都会得到一个ClassNotFoundException . 我使用jar命令创建了jar文件 . 另外,从协议缓冲消息生成person类 .

协议缓冲区的内容msg:

package testing;
option java_outer_classname = "AddressBookProtos";
option java_package = "com.sample";

message AddressBook {
  repeated Persons person = 1;
}

message Persons {
    required string name =1;
}

Scala文件:

object loaderTest extends App {

val classLoader = new URLCLassLoader(Array(new File("C:\\TEMP\\address.jar").toURI.toURL), this.getClass().getClassLoader())

val personClass = classLoader.loadClass("com.sample.AddressBookProtos$Persons")

}

线程“main”中的异常java.lang.ClassNotFoundException:com.sample.AddressBookProtos $ java.net.URLClassLoader的人员$ 1.run(URLClassLoader.java:202)java的java.security.AccessController.doPrivileged(Native Method) . net.URLClassLoader.findClass(URLClassLoader.java:190)位于java.lang.ClassLoader.loadClass(ClassLoader.java:306)的java.lang.ClassLoader.loadClass(ClassLoader.java:247)at com.ms.qaTools.protobuf .specs.loaderTest $ delayedInit $ body.apply(loaderTest.scala:34)at scala.Function0 $ class.apply $ mcV $ sp(Function0.scala:34)at scala.runtime.AbstractFunction0.apply $ mcV $ sp(AbstractFunction0) .scala:12)scala.App $$ anonfun $ main $ 1.apply(App.scala:60)at scala.App $$ anonfun $ main $ 1.apply(App.scala:60)at scala.collection.LinearSeqOptimized $ class.foreach(LinearSeqOptimized.scala:59)at scala.collection.immutable.List.foreach(List.scala:76)at scala.collection.generic.TraversableForwarder $ class.foreach(TraversableForwarder.scala:30)at scala.App $ class.main(App.scala:60)at com.ms.qaTo com.ms.qaTools.protobuf.specs.loaderTest.main(loaderTest.scala)中的ols.protobuf.specs.loaderTest $ .main(loaderTest.scala:10)