当前位置: 首页>>代码示例>>Scala>>正文


Scala JarFile类代码示例

本文整理汇总了Scala中java.util.jar.JarFile的典型用法代码示例。如果您正苦于以下问题:Scala JarFile类的具体用法?Scala JarFile怎么用?Scala JarFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了JarFile类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: KernelMgr

//设置package包名称以及导入依赖的类
package nasa.nccs.cds2.kernels
import java.util.jar.JarFile
import nasa.nccs.cdapi.kernels.KernelModule
import nasa.nccs.utilities.cdsutils
import collection.mutable
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._

class KernelMgr(  ) {

  val kernelModules = collectKernelModules()

  def getModule( moduleName: String ): Option[KernelModule] = kernelModules.get( moduleName.toLowerCase )

  def getModuleNames: List[String] = kernelModules.keys.toList

  def isKernelModuleJar(jarFile: JarFile): Boolean = cdsutils.getJarAttribute( jarFile, "Specification-Title" ) == "CDS2KernelModule"

  def getKernelModules(jarFile: JarFile): Iterator[KernelModule] =
    for( cls <- cdsutils.getClassesFromJar(jarFile); if cls.getSuperclass.getName == "nasa.nccs.cdapi.kernels.KernelModule") yield cls.getDeclaredConstructors()(0).newInstance().asInstanceOf[KernelModule]

  def toXml = <modules>{ kernelModules.values.map( _.toXml ) } </modules>

  def collectKernelModules(): Map[String, KernelModule] = {
    val kernelModules = new mutable.HashMap[String, KernelModule]()
    val cds = new nasa.nccs.cds2.modules.CDS.CDS()
    kernelModules += (cds.name.toLowerCase -> cds)
    for (jarFile <- cdsutils.getProjectJars; if isKernelModuleJar(jarFile); kmod <- getKernelModules(jarFile) ) kernelModules += (kmod.name -> kmod)
    kernelModules.toMap
  }
} 
开发者ID:nasa-nccs-cds,项目名称:CDASMerged,代码行数:32,代码来源:manager.scala

示例2: toUrl

//设置package包名称以及导入依赖的类
package jp.kenichi.lrcon
package server
package loader

import java.util.jar.JarFile
import java.util.zip.ZipException
import java.nio.file.{Path, Files}
import java.net.URLClassLoader


	def toUrl(path: Path) = {
		if (Files.isDirectory(path))
			path.toUri.toURL

		else if (Files.isRegularFile(path)) {
			try {
				// fail early if it is not a jar file
				new JarFile(path.toFile).close // verified if it is signed
				path.toUri.toURL

			} catch {
				case ex: ZipException => throw new Exception(s"failed to open a jar file: $path", ex)
			}

		} else {
			if (!Files.exists(path))
				throw new Exception(s"path does not exist: $path")

			else
				throw new Exception(s"not a directory nor regular file: $path")
		}
	}
} 
开发者ID:ken1ma,项目名称:lrcon,代码行数:34,代码来源:FileClassLoader.scala

示例3: 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)
              }
            })
          }
        }
      }
    }
  }
} 
开发者ID:Presageee,项目名称:nerver,代码行数:53,代码来源:HandlerScanner.scala


注:本文中的java.util.jar.JarFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。