【问题标题】:Datanucleus JDO in maven assembly jarMaven 程序集 jar 中的 Datanucleus JDO
【发布时间】:2012-05-13 21:44:43
【问题描述】:

我使用 maven 组装包创建了一个单一的整体 jar。包括 datanucleus 包,但我收到错误,因为我没有维护 OSGI 结构(plugins.xml 和 META-INF/META-INF.MD)。 stackoverflow([question]: Datanucleus, JDO and executable jar - how to do it?) 上的答案没有提供有关如何创建单个可部署 jar 的答案。

有谁知道我可以使用哪些 maven 指令来确保 OSGI 结构?

【问题讨论】:

    标签: java maven jar jdo datanucleus


    【解决方案1】:

    因此,问题在于将所有内容打包到一个整体 jar 中是 OSGI 结构会被其他 jar 的 OSGI 结构覆盖。单体 jar 的好处是有一个文件可以推送到服务器,但不是必需的(因为我使用 capistrano 推送到服务器)

    相反,将 jar 复制到最终构建目录中会更容易。 Heroku 的 Java 设置就是一个很好的例子:

    https://devcenter.heroku.com/articles/java

    <?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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <version>1.0-SNAPSHOT</version>
    <artifactId>helloworld</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-servlet</artifactId>
            <version>7.6.0.v20120127</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals><goal>copy-dependencies</goal></goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    </project>
    

    【讨论】:

    • 正确答案!人们有时非常热衷于创建这些整体罐子(有时称为 uberjars),但与此相关的各种陷阱。如果您可以部署为单独的 jar(或将尽可能多的 jar 打包到 WAR 等容器中),那么这是一种更好的方法。
    猜你喜欢
    • 2012-04-23
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-13
    • 2012-04-24
    • 1970-01-01
    • 2010-12-21
    相关资源
    最近更新 更多