指定“提供”。 maven 下与 grails 的依赖关系

发布于 2025-01-08 12:21:45 字数 12440 浏览 4 评论 0原文

我有一个 grails 1.3.7 应用程序。我正在利用 Spring 的 JMS 类将我的 grails 服务之一设置为消息侦听器,并在 grails-app/conf/resources.groovy 中设置这些类。我使用 maven 2.0.9 进行构建,使用 grails-maven-plugin 1.3.7 和“maven-war”目标来创建一个 war 文件。

我有两种情况:

  1. 我希望能够使用“mvn grails:run-app”从命令行在本地运行我的 grails 应用程序。我在开发过程中使用它。
  2. 我希望能够通过部署 maven 创建的 war 文件在 JBoss 5.1.0 GA 中运行应用程序。这就是我们在集成、测试和生产环境中所做的事情。

在 JBoss 内运行时,所有与 JMS 提供程序相关的依赖项均可用并由应用程序服务器提供。使用 maven 处理此问题的正常方法是在 pom 文件中声明这些依赖项,范围为“provided”。这将使这些依赖项可用于编译和单元测试,但将它们从 war 文件中排除。

然而,当我使用“mvn grails:run-app”从命令行本地运行时,这些依赖项似乎在运行时对 grails 不可用,许多 ClassNotFound 等异常就证明了这一点。将范围更改为“编译”允许我在本地运行。然而,现在这些依赖项被打包到我的 war 文件中,这是我不想要的,并且在 JBoss 中运行时往往会破坏一些东西。

我现在找到的解决方案(或解决方法)是在我的 pom 中包含默认(编译)范围的这些 JMS 依赖项,并通过 BuildConfig.groovy 中的一些代码从 war 文件中删除这些 jar(及其所有传递依赖项)(见下文)。这是可行的,但它很混乱并且容易出错,因为我必须列出每个传递依赖项(其中有很多!)。

我尝试过的其他一些事情:

首先,我想也许我可以将所需的 JMS 依赖项添加到 BuildConfig.groovy 中的“grails.project.dependency.resolution/dependency”部分,并将它们完全排除在 pom 之外。但是,这不起作用,因为根据 此链接,在maven下运行grails时,BuildConfig依赖部分会被忽略。

我还注意到“pom true”选项(在上面的链接中提到)并尝试使用它。但是,当尝试运行 grails:run-app 时,grails 会抛出有关未解决的依赖项的警告并给出 tomcat 错误:

:::: WARNINGS
::::::::::::::::::::::::::::::::::::::::::::::
::          UNRESOLVED DEPENDENCIES         ::
::::::::::::::::::::::::::::::::::::::::::::::
:: commons-collections#commons-collections;3.2.1: configuration not found in commons-collections#commons-collections;3.2.1: 'master'. It was required from org.grails.internal#load-manager-grails;1.2-SNAPSHOT compile
:: org.slf4j#slf4j-api;1.5.8: configuration not found in org.slf4j#slf4j-api;1.5.8: 'master'. It was required from org.grails.internal#load-manager-grails;1.2-SNAPSHOT runtime

...

java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.apache.tomcat.util.digester.Digester.setDocumentLocator(Lorg/xml/sax/Locator;)V" the class loader (instance of org/codehaus/groovy/grails/cli/support/GrailsRootLoader) of the current class, org/apache/tomcat/util/digester/Digester, and its superclass loader (instance of <bootloader>), have different Class objects for the type org/xml/sax/Locator used in the signature
        at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212)

我的问题: 有没有更好的方法 - 通过 grails 和/或 maven 配置选项 - 来完成我想要的 - 即能够在本地和 JBoss 中成功运行 grails,而无需手动从 war 文件中排除所有传递依赖项? >

注意:我无法更改我正在使用的 grails、JBoss 或 maven 的版本。

相关文件的一些摘录:

BuildConfig.groovy:

grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.war.file = "target/${appName}-${appVersion}.war"

grails.project.dependency.resolution = {
    // inherit Grails' default dependencies
    inherits("global") {
        // uncomment to disable ehcache
        // excludes 'ehcache'
    }
    log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    repositories {
        // only use our internal Archiva instance
        mavenRepo "http://my-company.com/archiva/repository/mirror"
        mavenLocal()
    }
    dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
    }

    //Remove own log4j and use the one supplied by JBoss instead
    grails.war.resources = {stagingDir ->
        delete file:"$stagingDir/WEB-INF/classes/log4j.properties" // logging conf done in JBoss only

        def files = fileScanner {
            fileset(dir:"$stagingDir/WEB-INF/lib"){
                [
                    // all of the following are jms-related dependencies supplied by JBoss
                    /* org.jboss.javaee */ "jboss-jms-api-*.jar",
                    /* org.jboss.naming */ "jnp-client-*.jar",
                    /*    org.jboss */ "jboss-common-core-*.jar",
                    /*    org.jboss.logging */ "jboss-logging-spi-*.jar",
                    /* jboss.messaging */ "jboss-messaging-*.jar",
                    /* org.jboss.aop */ "jboss-aop-*.jar",
                    /*    org.apache.ant */ "ant-*.jar",
                    /*        org.apache.ant */ "ant-launcher-*.jar",
                    /*    org.jboss */ "jboss-reflect-*.jar",
                    /*    org.jboss */ "jboss-mdr-*.jar",
                    /*    qdox */ "qdox-*.jar",
                    /*    trove */ "trove-*.jar",
                    /*    org.jboss.logging */ "jboss-logging-log4j-*.jar",
                    /* org.jboss.remoting */ "jboss-remoting-*.jar",
                    /* jboss */ "jboss-serialization-*.jar",
                    /* oswego-concurrent */ "concurrent-*.jar",
                    /* org.jboss.jbossas */ "jboss-as-cluster-*-jboss-ha-legacy-client.jar",
                    /*    commons-logging */ "commons-logging-*.jar",
                    /*    org.jboss.jbossas */ "jboss-as-server-*.jar",
                    /*       sun-jaxb */ "jaxb-api-*.jar",
                    /*       org.jboss.jbossas */ "jboss-as-deployment-*.jar",
                    /*          org.jboss.javaee */ "jboss-jad-api-*.jar",
                    /*          org.jboss.security */ "jboss-security-spi-*.jar",
                    . . . // and the other 74 transitive dependencies...
                ].each{
                    include(name:it)
                }
            }
        }
        files.each
        {
            delete(file: it)
        }

    }
}

pom.xml:

<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    . . .

    <dependencies>

        . . .

        <dependency>
            <!-- already a dep of grails-crud; make it scope:compile for resources.groovy -->
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
            <version>3.0.5.RELEASE</version>
        </dependency>
        <!-- Note: all the remaining jms dependencies below should be 'provided' scope, but
             grails doesn't correctly pull them in when running locally, so we must leave
             them as compile scope and remove them (and their transitive dependencies) from
             the war file through BuildConfig.groovy
        -->
        <dependency>
            <groupId>org.jboss.javaee</groupId>
            <artifactId>jboss-jms-api</artifactId>
            <version>1.1.0.GA</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.naming</groupId>
            <artifactId>jnp-client</artifactId>
            <version>5.0.3.GA</version>
        </dependency>
        <dependency>
            <groupId>jboss.messaging</groupId>
            <artifactId>jboss-messaging</artifactId>
            <version>1.4.3.GA</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.aop</groupId>
            <artifactId>jboss-aop</artifactId>
            <version>2.1.1.GA</version>
            <classifier>client</classifier>
            <exclusions>
                <exclusion>
                    <!-- see http://jira.codehaus.org/browse/GROOVY-3356 -->
                    <groupId>apache-xerces</groupId>
                    <artifactId>xml-apis</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.jboss.remoting</groupId>
            <artifactId>jboss-remoting</artifactId>
            <version>2.5.3.SP1</version>
        </dependency>
        <dependency>
            <groupId>jboss</groupId>
            <artifactId>jboss-serialization</artifactId>
            <version>1.0.3.GA</version>
        </dependency>
        <dependency>
            <groupId>oswego-concurrent</groupId>
            <artifactId>concurrent</artifactId>
            <version>1.3.4-jboss-update1</version>
        </dependency>
        <!-- the following two are required in order to connect to HA-JNDI -->
        <dependency>
            <groupId>org.jboss.jbossas</groupId>
            <artifactId>jboss-as-cluster</artifactId>
            <classifier>jboss-ha-legacy-client</classifier>
            <version>5.1.0.GA</version>
        </dependency>
        <dependency> 
            <groupId>org.jboss.cluster</groupId>
            <artifactId>jboss-ha-client</artifactId>
            <version>1.1.1.GA</version>
        </dependency>

        <!-- End dependencies for connecting to JMS -->

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.grails</groupId>
                <artifactId>grails-maven-plugin</artifactId>
                <version>1.3.7</version>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <goals>
                            <goal>init</goal>
                            <goal>maven-clean</goal>
                            <goal>validate</goal>
                            <goal>config-directories</goal>
                            <goal>maven-compile</goal>
                            <goal>maven-test</goal>
                            <goal>maven-war</goal>
                            <goal>maven-functional-test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

resources.groovy:

import org.codehaus.groovy.grails.commons.ConfigurationHolder
import org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter
import org.springframework.jms.listener.DefaultMessageListenerContainer
import org.springframework.jms.listener.adapter.MessageListenerAdapter
import org.springframework.jms.support.destination.JndiDestinationResolver
import org.springframework.jndi.JndiObjectFactoryBean
import org.springframework.jndi.JndiTemplate

beans = {

    def config = ConfigurationHolder.config

    jndiTemplate(JndiTemplate) {
        environment = config.myQueue.ctx.toProperties() // flattens a{b{c}} to 'a.b.c'
    }

    jmsFactory(JndiObjectFactoryBean) {
        jndiTemplate = jndiTemplate
        jndiName = config.myQueue.connectionFactory as String
        lookupOnStartup = false // need this?
        proxyInterface = "javax.jms.ConnectionFactory"
    }

    authJmsFactory(UserCredentialsConnectionFactoryAdapter) {
        targetConnectionFactory = jmsFactory
        username = config.app.auth.username as String
        password = config.app.auth.password as String
    }

    destinationResolver(JndiDestinationResolver) {
        jndiTemplate = jndiTemplate
    }

    jmsMessageListener(MessageListenerAdapter, ref("myMessageDrivenService")) {
        defaultListenerMethod = "onEventMessage"
    }

    jmsContainer(DefaultMessageListenerContainer) {
        connectionFactory = authJmsFactory
        destinationResolver = destinationResolver
        destinationName = config.eventQueue.queueName as String
        messageListener = jmsMessageListener
        transactionManager = ref("transactionManager") // grails' txn mgr
        cacheLevel = DefaultMessageListenerContainer.CACHE_CONNECTION
        autoStartup = false // started up in Bootstrap.groovy
    }
}

I have a grails 1.3.7 application. I am making use of Spring's JMS classses to set up one of my grails services as a message listener, setting up those classes in grails-app/conf/resources.groovy. I am using maven 2.0.9 for builds, using the grails-maven-plugin 1.3.7 and the "maven-war" goal to create a war file.

I have two scenarios:

  1. I want to be able to run my grails app locally, from the command line, using "mvn grails:run-app". I use this during development.
  2. I want to be able to run app within JBoss 5.1.0 GA, by deploying the war file created by maven. This is what we do in our integration, test and production environments.

When running inside JBoss, all of the JMS-provider-related dependencies are available and provided by the application server. The normal way of handling this with maven is to declare these dependencies in the pom file, with scope of "provided". This will make these dependencies available for compilation and unit tests, but exclude them from the war file.

However, when I run locally from the command line using "mvn grails:run-app", it appears that these dependencies are not available to grails at run-time, as evidenced by many ClassNotFound, etc. exceptions. Changing the scope to "compile" allows me to run locally. However, now these dependencies get packaged into my war file, which I do not want and tends to break things when running inside JBoss.

The solution (or workaround) I have found for now is to include these JMS dependencies with default (compile) scope in my pom, and remove these jars (and all their transitive dependencies) from the war file through some code in BuildConfig.groovy (see below). This works, but it's messy and error prone because I have to list every single transitive dependency (of which there are many!).

Some other things I have tried:

At first, I thought perhaps I could add the required JMS dependencies to BuildConfig.groovy, in the "grails.project.dependency.resolution / dependencies" section, and leave them out of the pom completely. However, this didn't work because, according to this link, the BuildConfig dependencies section is ignored when running grails under maven.

I also noticed the "pom true" option (mentioned in the link above) and tried to use it. However, when trying to run grails:run-app, grails throws warnings about unresolved dependencies and gives a tomcat error:

:::: WARNINGS
::::::::::::::::::::::::::::::::::::::::::::::
::          UNRESOLVED DEPENDENCIES         ::
::::::::::::::::::::::::::::::::::::::::::::::
:: commons-collections#commons-collections;3.2.1: configuration not found in commons-collections#commons-collections;3.2.1: 'master'. It was required from org.grails.internal#load-manager-grails;1.2-SNAPSHOT compile
:: org.slf4j#slf4j-api;1.5.8: configuration not found in org.slf4j#slf4j-api;1.5.8: 'master'. It was required from org.grails.internal#load-manager-grails;1.2-SNAPSHOT runtime

...

java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.apache.tomcat.util.digester.Digester.setDocumentLocator(Lorg/xml/sax/Locator;)V" the class loader (instance of org/codehaus/groovy/grails/cli/support/GrailsRootLoader) of the current class, org/apache/tomcat/util/digester/Digester, and its superclass loader (instance of <bootloader>), have different Class objects for the type org/xml/sax/Locator used in the signature
        at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212)

My question:
Is there a better way - through grails and/or maven configuration options - to accomplish what I want - i.e. to be able to run grails successfully locally and within JBoss, without having to manually exclude all transitive dependencies from the war file?

Note: I cannot change the version of grails, JBoss or maven that I am using.

Some excerpts of relevant files:

BuildConfig.groovy:

grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.war.file = "target/${appName}-${appVersion}.war"

grails.project.dependency.resolution = {
    // inherit Grails' default dependencies
    inherits("global") {
        // uncomment to disable ehcache
        // excludes 'ehcache'
    }
    log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    repositories {
        // only use our internal Archiva instance
        mavenRepo "http://my-company.com/archiva/repository/mirror"
        mavenLocal()
    }
    dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
    }

    //Remove own log4j and use the one supplied by JBoss instead
    grails.war.resources = {stagingDir ->
        delete file:"$stagingDir/WEB-INF/classes/log4j.properties" // logging conf done in JBoss only

        def files = fileScanner {
            fileset(dir:"$stagingDir/WEB-INF/lib"){
                [
                    // all of the following are jms-related dependencies supplied by JBoss
                    /* org.jboss.javaee */ "jboss-jms-api-*.jar",
                    /* org.jboss.naming */ "jnp-client-*.jar",
                    /*    org.jboss */ "jboss-common-core-*.jar",
                    /*    org.jboss.logging */ "jboss-logging-spi-*.jar",
                    /* jboss.messaging */ "jboss-messaging-*.jar",
                    /* org.jboss.aop */ "jboss-aop-*.jar",
                    /*    org.apache.ant */ "ant-*.jar",
                    /*        org.apache.ant */ "ant-launcher-*.jar",
                    /*    org.jboss */ "jboss-reflect-*.jar",
                    /*    org.jboss */ "jboss-mdr-*.jar",
                    /*    qdox */ "qdox-*.jar",
                    /*    trove */ "trove-*.jar",
                    /*    org.jboss.logging */ "jboss-logging-log4j-*.jar",
                    /* org.jboss.remoting */ "jboss-remoting-*.jar",
                    /* jboss */ "jboss-serialization-*.jar",
                    /* oswego-concurrent */ "concurrent-*.jar",
                    /* org.jboss.jbossas */ "jboss-as-cluster-*-jboss-ha-legacy-client.jar",
                    /*    commons-logging */ "commons-logging-*.jar",
                    /*    org.jboss.jbossas */ "jboss-as-server-*.jar",
                    /*       sun-jaxb */ "jaxb-api-*.jar",
                    /*       org.jboss.jbossas */ "jboss-as-deployment-*.jar",
                    /*          org.jboss.javaee */ "jboss-jad-api-*.jar",
                    /*          org.jboss.security */ "jboss-security-spi-*.jar",
                    . . . // and the other 74 transitive dependencies...
                ].each{
                    include(name:it)
                }
            }
        }
        files.each
        {
            delete(file: it)
        }

    }
}

pom.xml:

<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    . . .

    <dependencies>

        . . .

        <dependency>
            <!-- already a dep of grails-crud; make it scope:compile for resources.groovy -->
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
            <version>3.0.5.RELEASE</version>
        </dependency>
        <!-- Note: all the remaining jms dependencies below should be 'provided' scope, but
             grails doesn't correctly pull them in when running locally, so we must leave
             them as compile scope and remove them (and their transitive dependencies) from
             the war file through BuildConfig.groovy
        -->
        <dependency>
            <groupId>org.jboss.javaee</groupId>
            <artifactId>jboss-jms-api</artifactId>
            <version>1.1.0.GA</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.naming</groupId>
            <artifactId>jnp-client</artifactId>
            <version>5.0.3.GA</version>
        </dependency>
        <dependency>
            <groupId>jboss.messaging</groupId>
            <artifactId>jboss-messaging</artifactId>
            <version>1.4.3.GA</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.aop</groupId>
            <artifactId>jboss-aop</artifactId>
            <version>2.1.1.GA</version>
            <classifier>client</classifier>
            <exclusions>
                <exclusion>
                    <!-- see http://jira.codehaus.org/browse/GROOVY-3356 -->
                    <groupId>apache-xerces</groupId>
                    <artifactId>xml-apis</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.jboss.remoting</groupId>
            <artifactId>jboss-remoting</artifactId>
            <version>2.5.3.SP1</version>
        </dependency>
        <dependency>
            <groupId>jboss</groupId>
            <artifactId>jboss-serialization</artifactId>
            <version>1.0.3.GA</version>
        </dependency>
        <dependency>
            <groupId>oswego-concurrent</groupId>
            <artifactId>concurrent</artifactId>
            <version>1.3.4-jboss-update1</version>
        </dependency>
        <!-- the following two are required in order to connect to HA-JNDI -->
        <dependency>
            <groupId>org.jboss.jbossas</groupId>
            <artifactId>jboss-as-cluster</artifactId>
            <classifier>jboss-ha-legacy-client</classifier>
            <version>5.1.0.GA</version>
        </dependency>
        <dependency> 
            <groupId>org.jboss.cluster</groupId>
            <artifactId>jboss-ha-client</artifactId>
            <version>1.1.1.GA</version>
        </dependency>

        <!-- End dependencies for connecting to JMS -->

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.grails</groupId>
                <artifactId>grails-maven-plugin</artifactId>
                <version>1.3.7</version>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <goals>
                            <goal>init</goal>
                            <goal>maven-clean</goal>
                            <goal>validate</goal>
                            <goal>config-directories</goal>
                            <goal>maven-compile</goal>
                            <goal>maven-test</goal>
                            <goal>maven-war</goal>
                            <goal>maven-functional-test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

resources.groovy:

import org.codehaus.groovy.grails.commons.ConfigurationHolder
import org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter
import org.springframework.jms.listener.DefaultMessageListenerContainer
import org.springframework.jms.listener.adapter.MessageListenerAdapter
import org.springframework.jms.support.destination.JndiDestinationResolver
import org.springframework.jndi.JndiObjectFactoryBean
import org.springframework.jndi.JndiTemplate

beans = {

    def config = ConfigurationHolder.config

    jndiTemplate(JndiTemplate) {
        environment = config.myQueue.ctx.toProperties() // flattens a{b{c}} to 'a.b.c'
    }

    jmsFactory(JndiObjectFactoryBean) {
        jndiTemplate = jndiTemplate
        jndiName = config.myQueue.connectionFactory as String
        lookupOnStartup = false // need this?
        proxyInterface = "javax.jms.ConnectionFactory"
    }

    authJmsFactory(UserCredentialsConnectionFactoryAdapter) {
        targetConnectionFactory = jmsFactory
        username = config.app.auth.username as String
        password = config.app.auth.password as String
    }

    destinationResolver(JndiDestinationResolver) {
        jndiTemplate = jndiTemplate
    }

    jmsMessageListener(MessageListenerAdapter, ref("myMessageDrivenService")) {
        defaultListenerMethod = "onEventMessage"
    }

    jmsContainer(DefaultMessageListenerContainer) {
        connectionFactory = authJmsFactory
        destinationResolver = destinationResolver
        destinationName = config.eventQueue.queueName as String
        messageListener = jmsMessageListener
        transactionManager = ref("transactionManager") // grails' txn mgr
        cacheLevel = DefaultMessageListenerContainer.CACHE_CONNECTION
        autoStartup = false // started up in Bootstrap.groovy
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜巴黎 2025-01-15 12:21:45

解决方案是通过配置文件为您的依赖项创建动态范围。

示例:

<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

. . .
<properties>
   <jms.deps.scope>compile</jms.deps.scope>
</properties>

<profile>
   <id>build</id>
   <properties>
       <jms.deps.scope>provided</jms.deps.scope>
   </properties>
</profile>

<dependencies>
   <dependency>
      <groupId>whatever</groupId>
      <artifactId>whatever</artifactId>
      <scope>${jms.deps.scope}</scope>
   </dependency>
</dependencies>

. . .

然后当您的命令行将指定配置文件时:

mvn clean install war -P build

希望这会有所帮助。

The solution for this is to create a dynamic scope for your dependency through a profile.

Example:

<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

. . .
<properties>
   <jms.deps.scope>compile</jms.deps.scope>
</properties>

<profile>
   <id>build</id>
   <properties>
       <jms.deps.scope>provided</jms.deps.scope>
   </properties>
</profile>

<dependencies>
   <dependency>
      <groupId>whatever</groupId>
      <artifactId>whatever</artifactId>
      <scope>${jms.deps.scope}</scope>
   </dependency>
</dependencies>

. . .

Then when your command line will specify the profile:

mvn clean install war -P build

Hope this helps.

偏闹i 2025-01-15 12:21:45

这在 Grails 2.0 中已被“修复”。 grails 的 maven 插件已更新,因此“provided”范围意味着依赖项在本地运行时可用,但不包含在包 war 文件中。

This has been "fixed" in Grails 2.0. The maven plugin for grails has been updated so that the "provided" scope means that the dependency is available when running locally, but is not included in the package war file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文