本文整理汇总了Scala中java.util.jar.JarEntry类的典型用法代码示例。如果您正苦于以下问题:Scala JarEntry类的具体用法?Scala JarEntry怎么用?Scala JarEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JarEntry类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: HandlerScanner
//设置package包名称以及导入依赖的类
package org.nerver.core
import java.util
import java.util.jar.{JarEntry, JarFile}
import org.nerver.core.annotation.{Handler, Mapping}
import org.nerver.core.server.BaseServer
import org.nerver.core.utils.PathUtil
import scala.util.Try
class HandlerScanner(pkg: String) {
val url = getClass.getResource("")
def init(): Unit = {
val path = PathUtil.getPath(url.getPath)
loadJar(path)
}
def loadJar(path: String): Unit = {
val jarFile = new JarFile(path)
val entries: util.Enumeration[JarEntry] = jarFile.entries()
while (entries.hasMoreElements) {
val entry = entries.nextElement()
val name = entry.getName
if (name.contains(pkg)) {
println(name)
//auto scanner handler
Try{
val className = name.substring(0, name.lastIndexOf(".")).replaceAll("/", ".")
val clazz = Class.forName(className)
val an = clazz.getAnnotation(classOf[Handler])
if (null != an) {
//val obj = clazz.newInstance()
val methods = clazz.getDeclaredMethods
methods.foreach(m => {
Try{
val methodAnnotation = m.getAnnotation(classOf[Mapping])
val route = methodAnnotation.value()
val methodType = methodAnnotation.method()
BaseServer.typeMap(methodType) += (route -> clazz)
BaseServer.methodTypeMap(methodType) += (route -> m)
}
})
}
}
}
}
}
}