剔除动态生成的类路径罐子? [英] Excluding jars from dynamically generated classpaths?

查看:102
本文介绍了剔除动态生成的类路径罐子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从一个bash脚本启动我的Java服务器。该服务器提供了关于第三方jar文件的依赖。然而,其中一些罐子在我的应用程序罐子的冲突,并需要从classpath中排除...

I'm launching my java server from a bash script. The server has "provided" dependencies on 3rd party jars. However, some of those jars conflict with jars in my app, and need to be excluded from the classpath...

目前,我只需要排除一个罐子,所以这个成语用

At the moment, I only need to exclude one jar, so this idiom gets me by

EXTERNAL_JARS=$(find "${EXTERNAL_LIB}" -name 'slf4j-log4j12-1.4.3.jar' -prune -o -type f -name '*.jar' -printf ':%p' )
CLASSPATH=${CLASSPATH}${EXTERNAL_JARS}

有没有更好的办法,当外部罐的数量是20-30和排除罐的数量是用〜5?

Is there a better approach to use when the number of external jars is 20-30 and the number of excluded jars is ~ 5 ?

推荐答案

这会工作,但它假定你不能有空格的文件名。

This would work, although it assumes that you don't have spaces in your filenames.

EXCLUDED="slf4j-log4j12-1.4.3.jar
some-other-library.jar
something-else.jar"

EXTERNAL_JARS=$(
  find "${EXTERNAL_LIB}" -type f -name '*.jar' \
    | grep -v -F"$EXCLUDED" \
    | xargs \
    | tr ' ' ':'
)

CLASSPATH=${CLASSPATH}:${EXTERNAL_JARS}

这里的想法是使用的grep -v -F 和多行字符串变量过滤掉排除罐子。

The idea here is to use grep -v -F and a multi-line string variable to filter out the excluded jars.

当你这样做,你不能再使用 -printf 标志找到,所以你更换与 xargs的| TR''' - '。在这里,的xargs 将连接所有的罐子,它们与一个空格和 TR 命令替换这些空间用冒号分隔。同样,如果你没有在你的路径空间,这将正常工作。

When you do that, you can no longer use the -printf flag in find, so you replace it with xargs | tr ' ' '-'. Here xargs will concatenate all the jars, separating them with a space and the tr command replaces those spaces with colons. Again, this will work if you don't have spaces in your path.

这篇关于剔除动态生成的类路径罐子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆