简体   繁体   English

如何从 Maven 项目中自动排除未使用的 jar 文件?

[英]How to automatically exclude not-used jar files from a maven project?

If I would like to write a program to automatically exclude not-used jar files from a maven project (regardless of what programming language I will use), how should I get start?如果我想编写一个程序来自动从 Maven 项目中排除未使用的 jar 文件(无论我将使用哪种编程语言),我应该如何开始?

Currently, I have a stupid idea.目前,我有一个愚蠢的想法。 Except the declared jar files, every time excluding a node of the dependency tree top down, then compile and run the project to see whether this jar file could be excluded.除了声明的jar文件,每次自顶向下排除依赖树的一个节点,然后编译运行项目,看是否可以排除这个jar文件。

I cannot find any other better ideas and I need help.我找不到任何其他更好的想法,我需要帮助。 Please share me with whatever come into your minds.请与我分享您想到的任何内容。 If you know somebody else has done this before, please post the link to the source code or share with me its ideas.如果你知道其他人以前做过这件事,请张贴源代码的链接或与我分享它的想法。 Thanks!!!!谢谢!!!!

By the way, what if I want to write a program automatically solving the dependency conflict problems?顺便问一下,如果我想写一个程序自动解决依赖冲突问题怎么办? Is this possible?这可能吗? I know Such problems have bothered java developers a lot.我知道这些问题一直困扰着 Java 开发人员。

The idea of compiling for every removed dependency is good, but don't forget to launch the program also (some dependencies are required at runtime only).为每个删除的依赖项编译的想法是好的,但也不要忘记启动程序(某些依赖项仅在运行时才需要)。

I had to do that a few times, but I did manually (not automatically with a program), i removed all dependencies and added them one by one until code compiles, and until the program run OK.我不得不这样做几次,但我是手动完成的(不是用程序自动完成的),我删除了所有依赖项并一个一个地添加它们,直到代码编译,直到程序运行正常。

The problem with approaches like this is the fact that even though everything might compile correctly, you are missing resources during runtime.这种方法的问题在于,即使一切都可能正确编译,但您在运行时会丢失资源。

That might be the case, if you load classes and stuff with help of the Classloader or if you are using reflection to access classes and methods.如果您在类加载器的帮助下加载类和内容,或者如果您使用反射来访问类和方法,则可能是这种情况。 This gets even worse if you look at more dynamic languages aside of Java: the compiler won't help you that much anymore如果您查看 Java 之外的更多动态语言,情况会变得更糟:编译器将不再为您提供太多帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM