简体   繁体   English

我是否可以创建一个Maven项目,期望包含它的任何人都可以实现任意Java-ee 6库?

[英]Can I create a Maven project that expects anyone who includes it to have an implementation of an arbitrary Java-ee 6 library?

I am creating a project that will be useful for anyone with a java-ee environment. 我正在创建一个项目,该项目对具有java-ee环境的任何人都将有用。 I wan't to include the bare bones java-ee interface library in my project to allow me to code with all of the EJB annotations but i would rather make it's scope provided so as not to import all the classes into my project. 我不想在项目中包括裸露的java-ee接口库,以允许我使用所有EJB注释进行编码,但是我希望使其具有作用域provided以免将所有类都导入到我的项目中。

Is there a way I can make this dependency and require any user to have a java-ee library or do I have to make something like maven profiles that activate when it detects each server type, (ie one for jboss, one for glassfish, websphere, etc...). 有没有一种方法可以使我依赖于此关系,并要求任何用户都具有java-ee库,或者我必须做一些类似maven的配置文件来在检测到每种服务器类型时激活(例如,一个用于jboss,一个用于glassfish,websphere)等)。

my pom looks like this: 我的pom看起来像这样:

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>project-that-wants-users-to-have-javaee-libraries</artifactId>
    <version>0.0.1-Pre-alpha</version>

    <dependencies>
        ....
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>

EDIT: just to clarify what I Am asking, Say I have a maven project like so: 编辑:只是为了澄清我要问的,说我有一个像这样的Maven项目:

<?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/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>testEJBProject</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-all-6.0</artifactId>
            <version>3.0.2.Final</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>project-that-wants-users-to-have-javaee-libraries</artifactId>
            <version>0.0.1-Pre-alpha</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.jboss.as.plugins</groupId>
                <artifactId>jboss-as-maven-plugin</artifactId>
                <version>7.4.Final</version>
            </plugin>
        </plugins>
    </build>
</project>

will the dependency in my code be satisfied at runtime even though i'm specifically using the jboss-javaee-all-6.0 api and plugin? 即使我专门使用jboss-javaee-all-6.0 api和插件,运行时也会满足我代码中的依赖关系吗?

It is my understanding that specifying the java api's and scoping them to provided will cause the dependency to expect anything using it to already have the implementations of those api's on the class path. 据我了解,指定Java api并对其进行范围界定将导致依赖项期望使用它的任何东西都已经在类路径上具有这些api的实现。 you specify a dependency as provided like so: 您指定为依赖性provided像这样:

<dependencies>
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>tobeprovidedproject</artifactId>
        <version>1.0.0.Final</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

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

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