scala – 编译后从类路径中删除条目
我有一个依赖于jar项目的遗留战争项目,jar项目需要在类路径中添加一些非托管jar进行编译.但这些罐子不应该包装在战争中.所以我的问题是如何从fullClasspath中删除这些条目.以下内容不起作用:
val excludeFilter = "(servlet-api.jar)|(gwt-dev.jar)|(gwt-user.jar)" val filteredCP = cp.flatMap({ entry => val jar = entry.data.getName() if (jar.matches(excludeFilter)) { Nil } else { Seq(entry) } }) fullClasspath in Runtime = filteredCP 我很确定必须有简单的方法来做到这一点但到目前为止它已经让我望而却步. 编辑:根据Pablo的使用托管类路径而不是非托管类的消息,我可以将问题重新解释为:如何将本地jar添加到managedClasspath.我的罐子放在一个带有(非常)非标准布局的本地文件夹中: lib/testng.jar lib/gwt/2.3/gwt-user.jar lib/jetty/servlet.jar 所以基本上我正在寻找类似的东西: libraryDependencies += "testng" % "provided->test" libraryDependencies += "gwt" % "2.3" % "gwt-user" % "provided->compile" libraryDependencies += "jetty" % "servlet" % "provided->default" 允许我从我自己的本地lib文件夹中获取jar. 解决方法
有些信息在
Classpaths页面上提供,但不是很清楚或详细.使用inspect命令也可以获得该信息,如
Inspecting Settings页面所述.
基本上,对于配置X,用简写符号表示: // complete,exported classpath,such as used by // 'run','test','console',and the war task fullClasspath in X = dependencyClasspath in X ++ exportedProducts in X // classpath only containing dependencies,// used by 'compile' or 'console-quick',for example dependencyClasspath in X = externalDependencyClasspath in X ++ internalDependencyClasspath in X // classpath containing only dependencies external to the build // (as opposed to the inter-project dependencies in internalDependencyClasspath) externalDependencyClasspath in X = unmanagedClasspath in X ++ managedClasspath in X // the manually provided classpath unmanagedClasspath in X = unmanagedJars for X and all configurations X extends,transitively 因此,通常,当您想要添加非托管库时,可以将它们添加到unmanagedJars.例如,如果在Compile中向unmanagedJars添加库,那么sbt将在unmanagedClasspath上正确地包含用于Compile,Runtime和Test的库. 但是,您需要在此处进行显式控制.仅将库添加到您希望打开jar的unmanagedClasspath,这是在Compile中的unmanagedClasspath.例如,在sbt 0.11.0中: unmanagedClasspath in Compile <++= baseDirectory map { base => val lib = base / "lib" Seq( lib / "testng.jar",lib / "gwt/2.3/gwt-user.jar",lib / "jetty/servlet.jar" ) } 假设war插件使用Runtime类路径,那些jar只会出现在编译类路径上,而不会出现在war中. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |