简体   繁体   English

Maven ejb-client生成依赖性排除

[英]Maven ejb-client generation dependency exclusion

We have a solution where our UI projects are including quite a bunch of business services by using the EJB client dependencies. 我们有一个解决方案,我们的UI项目通过使用EJB客户端依赖项包含了大量业务服务。 The problem with this on Maven is that even though the client .jar usually contains about 1-2 classes, they bring with them the full dependency stack of the entire service application. Maven上的问题在于,即使客户端.jar通常包含大约1-2个类,它们也会带来整个服务应用程序的完整依赖性堆栈。 This can get a bit ugly, when the .ear files start growing up to 50-100Mb a pop and there are from time to time pesky errors thanks to irrelevant dependencies sneaking their way into the UI application. 这可以得到一个有点难看,当的.ear文件开始成长到50-100Mb弹出有不时感谢无关依赖潜入的方式进入UI应用讨厌的错误。

Of course, we can always exclude the dependencies on the client end, but then we have to write the same bunch of lines to each client project using those services and that's a lot of needless repetition. 当然,我们总是可以排除客户端上的依赖关系,但是我们必须使用这些服务为每个客户端项目编写相同的一行,这是很多不必要的重复。 Plus, people come up with the weirdest error messages and use a lot of time tracking them down before remembering to mention that they included some client jar and didn't check what additional dependencies it brought into the equation. 此外,人们提出了最奇怪的错误消息并使用大量时间跟踪它们,然后再记得提到它们包含一些客户端jar并且没有检查它带来了什么额外的依赖性。

Example: 例:

        <dependency>
            <groupId>fi.path.to.service</groupId>
            <artifactId>customermanagement-common</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>fi.path.to.service</groupId>
            <artifactId>customermanagement-service</artifactId>
            <classifier>client</classifier>
            <exclusions>
                <exclusion>
                    <groupId>fi.path.to.dependency</groupId>
                    <artifactId>internal-dependency-#1</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.codehaus.castor</groupId>
                    <artifactId>castor</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>fi.path.to.dependency</groupId>
                    <artifactId>internal-dependency-#2</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>internal-dependency-#3</artifactId>
                    <groupId>fi.path.to.dependency</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>internal-dependency-#4</artifactId>
                    <groupId>fi.path.to.dependency</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>internal-dependency-#5</artifactId>
                    <groupId>fi.path.to.dependency</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>castor-xml</artifactId>
                    <groupId>org.codehaus.castor</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>castor-codegen</artifactId>
                    <groupId>org.codehaus.castor</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>castor-xml-schema</artifactId>
                    <groupId>org.codehaus.castor</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>internal-dependency-#6</artifactId>
                    <groupId>fi.path.to.dependency</groupId>
                </exclusion>
            </exclusions>
            <version>2.6</version>
        </dependency>

That is just one service client being included, imagine having several of these in several different applications and you get the picture, writing up all the excludes each time is quite annoying and the project POMs start getting fairly longwinded. 这只是一个服务客户端被包含在内,想象在几个不同的应用程序中有几个并且你得到了图片,每次写入所有排除非常烦人并且项目POM开始变得相当漫长。

I would mark the dependency as provided, but there are a couple dependencies that do crash on runtime, if they don't exist. 我会将依赖项标记为已提供,但是如果它们不存在,则会有一些依赖项在运行时崩溃。 Say ones that include another service call to yet another app with an external Exception class, which isn't for one reason or another wrapped inside the service project and will cause a ClassNotFoundException on runtime, if not present. 比如那些包含另一个带有外部Exception类的应用程序的服务调用,这不是出于某种原因而包含在服务项目中,并且如果不存在则会在运行时导致ClassNotFoundException。

Therefore, I know it's possible to exclude/include classes from an ejb client during its generation through the usage of pom.xml specs on the maven-ejb-plugin, but is there any way to exclude dependencies as well? 因此,我知道通过在maven-ejb-plugin上使用pom.xml规范,可以在ejb客户端生成期间排除/包含类,但是有没有办法排除依赖项?

Seems that Maven just doesn't support building multiple jars out of one module very well. 似乎Maven不支持很好地从一个模块中构建多个罐子。

Thus the only reasonable way around this that we've found is to create another module (break xxx-service into xxx-service and xxx-service-client) and configure the xxx-service-client module to have only the EJB client/delegate class & minimal dependencies. 因此,我们发现的唯一合理的方法是创建另一个模块(将xxx-service转换为xxx-service和xxx-service-client)并将xxx-service-client模块配置为仅具有EJB客户端/委托类和最小依赖项。 That way the project can be built with a single execution. 这样,项目就可以通过一次执行来构建。

I have the same problem here. 我在这里遇到同样的问题。 I think one solution could be using profiles, since in each profile you could specify the dependencies (see http://blog.sonatype.com/people/2010/01/how-to-create-two-jars-from-one-project-and-why-you-shouldnt/ ) 认为一个解决方案可能是使用配置文件,因为在每个配置文件中,您可以指定依赖项(请参阅http://blog.sonatype.com/people/2010/01/how-to-create-two-jars-from-one-项目 - 为什么你不应该/

In my case, this doesn't work, because I need to generate both JARs (ejb and ejb-client) in a single execution of Maven. 在我的情况下,这不起作用,因为我需要在Maven的单次执行中生成两个JAR(ejb和ejb-client)。 :) :)

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

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