简体   繁体   English

将JAR文件添加到web-inf / lib文件夹中,而不将其包含在pom.xml中

[英]Add JAR-File to web-inf/lib folder without including it in pom.xml

I am writing an application server using JBoss. 我正在使用JBoss编写应用程序服务器。 The application gets compiled by Maven and packaged as WAR. 该应用程序由Maven编译并打包为WAR。 Now I want to externalize some classes. 现在,我想外部化一些类。 I create another maven project, which is packaged as JAR. 我创建另一个打包为JAR的Maven项目。

The JAR has the correct directory tree, I believe. 我相信JAR具有正确的目录树。 It contains a META-INF directory and the package structure as directories, in which the class files reside. 它包含一个META-INF目录以及作为目录的包结构,类文件位于其中。

I read on the web that I can add this JAR into the app server by placing it into src\\main\\webapp\\WEB-INF\\lib without further mentioning it in the pom.xml of the appserver (at some point these JARs shall be plugins, so adding a dependency in the pom.xml is not an option). 我在网络上阅读到,可以将此JAR放入src\\main\\webapp\\WEB-INF\\lib并将其添加到应用服务器中,而无需在应用服务器的pom.xml中进一步提及(有时这些JAR应该是插件,因此不能在pom.xml中添加依赖项)。

When I compile the server, the JAR gets correctly copied into the WAR under WEB-INF\\lib , along with other external dependencies. 当我编译服务器时,将JAR与其他外部依赖项一起正确复制到WEB-INF\\lib下的WAR中。

However, when I try to use the class in the appserver, (writing an import statement of such a class is enough), maven will complain that it can't find the class. 但是,当我尝试在应用服务器中使用该类时(编写此类的import语句就足够了),maven会抱怨找不到该类。

I tried to find information on the web, but all I could find was that this is the way it's to be done. 我试图在Web上查找信息,但我能找到的只是这是要完成的方式。

Does anyone know where I could further look for clues what's going wrong? 有谁知道我可以在哪里进一步寻找线索哪里出了问题?

Putting the jar file into src\\main\\webapp\\WEB-INF\\lib is cumbersome, and plainly wrong. 将jar文件放入src\\main\\webapp\\WEB-INF\\lib很麻烦,这显然是错误的。

The reason that the code does not compile is that maven compiler plugin uses defined source paths and (provided and compile scoped) dependencies. 代码无法编译的原因是maven编译器插件使用了已定义的源路径和(提供和编译范围内的)依赖项。

You could change this, but the result would be hard to understand. 您可以更改此设置,但结果将难以理解。 Also, you would have to update your jar file (which, BTW has no place in your source code) by hand. 另外,您还必须手动更新jar文件(BTW在源代码中没有位置)。

Thats what dependency management is for. 那就是依赖管理的目的。

Don't work against your tool. 不要反对您的工具。 If your project needs classes from this jar, it is a dependency. 如果您的项目需要此jar中的类,则为依赖项。 So declare it as such. 因此就这样声明。

If you're talking about "plugins" then you shouldn't be importing the classes directly in your code anyway. 如果您在谈论“插件”,那么无论如何您都不应该直接在代码中导入类。 A common approach would be to define another module with interfaces that your plugins will implement, then have both your main webapp and the plugin projects depend on this interface module. 一种常见的方法是使用您的插件将要实现的接口定义另一个模块,然后让您的主webapp和插件项目都依赖于此接口模块。 In the main app you load plugin classes by reflection and cast them to the appropriate interface(s). 在主应用程序中,您通过反射加载插件类,并将其转换为适当的接口。 That way you don't depend directly on the plugins' concrete classes when compiling the host application. 这样,您在编译主机应用程序时就不会直接依赖于插件的具体类。

暂无
暂无

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

相关问题 Is it possible to have Maven “WAR” pom.xml package up my classes up in a JAR and put the JAR in the /WEB-INF/lib folder? - Is it possible to have Maven “WAR” pom.xml package up my classes up in a JAR and put the JAR in the /WEB-INF/lib folder? UCP jar依赖项存在于pom.xml中,但未出现在WEB-INF \\ lib中 - UCP jar dependency present in pom.xml but its not appearing inside WEB-INF\lib 在POM的WEB-INF \ lib中添加jar - Adding a jar in WEB-INF\lib in POM 如何将 JAR 文件添加到现有的 WAR 文件 web-inf/lib 文件夹中? - How to add JAR file to an existing WAR file web-inf/lib folder? 将Jar文件添加到WEB-INF / lib - Adding Jar File to WEB-INF/lib 频繁更改pom.xml / maven项目依赖项时,自动更新WEB-INF / lib目录的正确方法是什么? - What's the right way to automatically update WEB-INF/lib directory when pom.xml/maven project dependencies are changed frequently? 对于外部jar,如果jar已存在/已复制到lib文件夹,是否有必要在pom.xml文件中添加具有系统路径的依赖项 - For an external jar, is it necessary to add a dependency in pom.xml file with a system path if jar already present/copied to lib folder 在`WEB-INF / lib`文件夹中找不到jar文件的解决方案,也没有在`src / main / resources`文件夹中找到? - Solution for a jar file not findable in the `WEB-INF/lib` folder nor `src/main/resources` folder? Java jar文件正在WEB-INF / lib文件夹中删除 - java jar files are being deleted in the WEB-INF/lib folder Maven构建损坏/ WEB-INF / lib文件夹中的jar文件 - Maven build corrupting jar files in /WEB-INF/lib folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM