Maven和GlassFish3示例出错

时间:2013-07-05 07:31:34

标签: maven build osgi glassfish-3 apache-felix

我是所有这些OSGi和Maven的新手,我正在阅读Walid Gedeon所着的书籍OSGi and Apache Felix 3.0 - Beginner's Guide中的“Bookshelf”教程。

我已经按照他们的书中的例子,到目前为止部署我的代码时遇到了一些问题。

我收到以下错误消息:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Bookshelf Inventory API
[INFO]    task-segment: [clean, deploy]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory C:\com.packtpub.felix.bookshelf-inventory-api\target
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 6 source files to C:\com.packtpub.felix.bookshelf-inventory-api\target\classes
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\com.packtpub.felix.bookshelf-inventory-api\src\test\resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] No sources to compile
[INFO] [surefire:test {execution: default-test}]
[INFO] No tests to run.
[INFO] [bundle:bundle {execution: default-bundle}]
[WARNING] Warning building bundle com.packtpub.felix:com.packtpub.felix.bookshelf-inventory-api:bundle:1.5.0 : Instructions in Private-Package, or -testpackages that are never used: \.
[INFO] [install:install {execution: default-install}]
[INFO] Installing C:\com.packtpub.felix.bookshelf-inventory-api\target\com.packtpub.felix.bookshelf-inventory-api-1.5.0.jar to C:\Users\eivaore\.m2\repository\com\packtpub\felix\com.packtpub.felix.bookshelf-inventory-api\1.5.0\com.packtpub.felix.bookshelf-inventory-api-1.5.0.jar
[INFO] [bundle:install {execution: default-install}]
[INFO] Installing com/packtpub/felix/com.packtpub.felix.bookshelf-inventory-api/1.5.0/com.packtpub.felix.bookshelf-inventory-api-1.5.0.jar
[WARNING] Exception while updating local OBR: The header cannot be an empty string.
java.lang.IllegalArgumentException: The header cannot be an empty string.
    at org.apache.felix.utils.manifest.Parser.parseHeader(Parser.java:37)
    at org.apache.felix.bundlerepository.impl.DataModelHelperImpl.getSymbolicName(DataModelHelperImpl.java:871)
    at org.apache.felix.bundlerepository.impl.DataModelHelperImpl.populate(DataModelHelperImpl.java:519)
    at org.apache.felix.bundlerepository.impl.DataModelHelperImpl.createResource(DataModelHelperImpl.java:513)
    at org.apache.felix.bundlerepository.impl.DataModelHelperImpl.createResource(DataModelHelperImpl.java:404)
    at org.apache.felix.obrplugin.ObrUpdate.updateRepository(ObrUpdate.java:170)
    at org.apache.felix.obrplugin.ObrInstall.updateLocalBundleMetadata(ObrInstall.java:183)
    at org.apache.felix.obrplugin.ObrInstall.execute(ObrInstall.java:142)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
[INFO] [deploy:deploy {execution: default-deploy}]
Uploading: file:///C:/projects/felixbook/releases/com/packtpub/felix/com.packtpub.felix.bookshelf-inventory-api/1.5.0/com.packtpub.felix.bookshelf-inventory-api-1.5.0.jar
4/7K
7/7K
7K uploaded  (com.packtpub.felix.bookshelf-inventory-api-1.5.0.jar)
[INFO] Retrieving previous metadata from repo-rel
[INFO] Uploading repository metadata for: 'artifact com.packtpub.felix:com.packtpub.felix.bookshelf-inventory-api'
[INFO] Uploading project information for com.packtpub.felix.bookshelf-inventory-api 1.5.0
[INFO] [bundle:deploy {execution: default-deploy}]
[INFO] LOCK file:///C:/projects/felixbook/releases/repository.xml
[INFO] Downloading repository.xml
[INFO] Computed bundle uri: file:/C:/projects/felixbook/releases/com/packtpub/felix/com.packtpub.felix.bookshelf-inventory-api/1.5.0/com.packtpub.felix.bookshelf-inventory-api-1.5.0.jar
[INFO] Writing OBR metadata
[INFO] Deploying file:/C:/projects/felixbook/releases/com/packtpub/felix/com.packtpub.felix.bookshelf-inventory-api/1.5.0/com.packtpub.felix.bookshelf-inventory-api-1.5.0.jar
[WARNING] Exception while updating remote OBR: The header cannot be an empty string.
java.lang.IllegalArgumentException: The header cannot be an empty string.
    at org.apache.felix.utils.manifest.Parser.parseHeader(Parser.java:37)
    at org.apache.felix.bundlerepository.impl.DataModelHelperImpl.getSymbolicName(DataModelHelperImpl.java:871)
    at org.apache.felix.bundlerepository.impl.DataModelHelperImpl.populate(DataModelHelperImpl.java:519)
    at org.apache.felix.bundlerepository.impl.DataModelHelperImpl.createResource(DataModelHelperImpl.java:513)
    at org.apache.felix.bundlerepository.impl.DataModelHelperImpl.createResource(DataModelHelperImpl.java:404)
    at org.apache.felix.obrplugin.ObrUpdate.updateRepository(ObrUpdate.java:170)
    at org.apache.felix.obrplugin.ObrDeploy.updateRemoteBundleMetadata(ObrDeploy.java:351)
    at org.apache.felix.obrplugin.ObrDeploy.execute(ObrDeploy.java:253)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
[INFO] UNLOCK file:///C:/projects/felixbook/releases/repository.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5 seconds
[INFO] Finished at: Fri Jul 05 09:23:06 CEST 2013
[INFO] Final Memory: 18M/169M
[INFO] ------------------------------------------------------------------------

这是我的pom.xml

<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.packtpub.felix</groupId>
<artifactId>com.packtpub.felix.bookshelf-inventory-api</artifactId>
<version>1.5.0</version>

<packaging>bundle</packaging>

<name>Bookshelf Inventory API</name>
<description>Defines the API for the Bookshelf inventory</description>

<dependencies></dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.1.0</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-Category>sample</Bundle-Category>
                    <Bundle-SymbolicName>${artifactID}</Bundle-SymbolicName>

                    <Export-Package>
                        com.packtpub.felix.bookshelf.inventory.api
                    </Export-Package>
                </instructions>

                <remoteOBR>repo-rel</remoteOBR>
                <prefixUrl>
                    file:///C:/projects/felixbook/releases
                </prefixUrl>
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <inherited>true</inherited>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<distributionManagement>
    <!-- releases repo -->
    <repository>
        <id>repo-rel</id>
        <url>file:///C:/projects/felixbook/releases</url>
    </repository>
</distributionManagement>

有什么想法吗?

编辑:
从我注意到的问题出现在<packaging>bundle</packaging>

2 个答案:

答案 0 :(得分:1)

您应该尝试生成清单

<plugin>
  <groupId>org.apache.felix</groupId>
  <artifactId>maven-bundle-plugin</artifactId>
  <configuration>
    <supportedProjectTypes>
      <supportedProjectType>bundle</supportedProjectType>
      <supportedProjectType>war</supportedProjectType>
    </supportedProjectTypes>
  </configuration>
  <executions>
    <execution>
      <id>bundle-manifest</id>
      <phase>process-classes</phase>
      <goals>
        <goal>manifest</goal>
      </goals>
      <configuration>
        <!-- config and instructions here -->
      </configuration>
    </execution>
  </executions>
</plugin>

<plugin>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <archive>
      <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
    </archive>
  </configuration>
</plugin>

答案 1 :(得分:1)

抛出异常是因为Bundle-SymbolicName无效:pom.xml中的属性查找区分大小写(请查看pom.xml reference)。把它改成这样的东西:

<Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>