在Apache Karaf 4.0.0.M2上部署Spring webapp

时间:2015-03-25 13:18:17

标签: spring maven war apache-karaf

请在Apache Karaf中部署战争时帮助我解决以下错误。我使用maven来构建war文件。下面是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.test</groupId>
    <artifactId>MyApp</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>MyApp Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <properties>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
        <springframework.version>4.0.6.RELEASE</springframework.version>
        <servlet.version>3.1.0</servlet.version>
        <hibernate.version>4.3.8.Final</hibernate.version>
        <commons.version>1.4.1</commons.version>
        <mysql.version>5.1.34</mysql.version>
        <c3p0.version>0.9.1.2</c3p0.version>

    </properties>

    <dependencies>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.5</version>
        </dependency>

        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
            <version>${commons.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servlet.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${springframework.version}</version>
        </dependency>

        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>${c3p0.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-core</artifactId>
            <version>5.7.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.3.2</version>
        </dependency>

        <dependency>
            <groupId>fop</groupId>
            <artifactId>fop</artifactId>
            <version>0.20.5</version>
        </dependency>

        <dependency>
            <groupId>net.sf.jtidy</groupId>
            <artifactId>jtidy</artifactId>
            <version>r938</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>MyApp</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我能够构建战争可以在tomcat中成功部署它。但它在卡拉夫失败了。请参阅下面的karaf控制台。请帮助解决此问题。

karaf@root()> bundle:install -s "webbundle:file:///D:/MyApp.war?Web-ContextPath=/MyApp"
Bundle IDs:
Error executing command: Error installing bundles:
        Unable to install bundle webbundle:file:///D:/MyApp.war?Web-ContextPath=/MyApp
karaf@root()> log:display
2015-03-25 16:48:33,439 | ERROR | nsole user karaf | ShellUtil                        | 41 - org.apache.karaf.shell.core - 4.
0.0.M2 | Exception caught while executing command
org.apache.karaf.shell.support.MultiException: Error installing bundles:
        Unable to install bundle webbundle:file:///D:/MyApp.war?Web-ContextPath=/MyApp
        at org.apache.karaf.shell.support.MultiException.throwIf(MultiException.java:61)
        at org.apache.karaf.bundle.command.Install.execute(Install.java:116)[21:org.apache.karaf.bundle.core:4.0.0.M2]
        at org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:83)[41:org.apache.karaf.shell.
core:4.0.0.M2]
        at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:67)[41:org.apache.kara
f.shell.core:4.0.0.M2]
        at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:87)[41:org.apache.kara
f.shell.core:4.0.0.M2]
        at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)[41:org.apache.karaf.shell.core:4.0.0.M2]
        at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)[41:org.apache.karaf.shell.core:4.0.0.M2]
        at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[41:org.apache.karaf.shell.core:4.0.0.M2]
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)[41:org.apache.karaf.shell.core:4.0.0.M2]
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)[41:org.apache.karaf.shell.core:4.0.0.M2]
        at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)[41:org.apache.karaf.shell.cor
e:4.0.0.M2]
        at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:267)[41:org.apache.karaf.shell.
core:4.0.0.M2]
        at java.lang.Thread.run(Thread.java:744)[:1.8.0]
Caused by: java.lang.Exception: Unable to install bundle webbundle:file:///D:/MyApp.war?Web-ContextPath=/MyApp
        at org.apache.karaf.bundle.command.Install.execute(Install.java:79)[21:org.apache.karaf.bundle.core:4.0.0.M2]
        ... 11 more
Caused by: org.osgi.framework.BundleException: Duplicate import: javax.servlet.jsp
        at org.apache.felix.framework.util.manifestparser.ManifestParser.normalizeImportClauses(ManifestParser.java:366)[org.
apache.felix.framework-4.4.1.jar:]
        at org.apache.felix.framework.util.manifestparser.ManifestParser.<init>(ManifestParser.java:180)[org.apache.felix.fra
mework-4.4.1.jar:]
        at org.apache.felix.framework.BundleRevisionImpl.<init>(BundleRevisionImpl.java:121)[org.apache.felix.framework-4.4.1
.jar:]
        at org.apache.felix.framework.BundleImpl.createRevision(BundleImpl.java:1243)[org.apache.felix.framework-4.4.1.jar:]
        at org.apache.felix.framework.BundleImpl.<init>(BundleImpl.java:112)[org.apache.felix.framework-4.4.1.jar:]
        at org.apache.felix.framework.Felix.installBundle(Felix.java:2907)[org.apache.felix.framework-4.4.1.jar:]
        at org.apache.felix.framework.BundleContextImpl.installBundle(BundleContextImpl.java:165)[org.apache.felix.framework-
4.4.1.jar:]
        at org.apache.karaf.bundle.command.Install.execute(Install.java:77)[21:org.apache.karaf.bundle.core:4.0.0.M2]
        ... 11 more

karaf@root()>

1 个答案:

答案 0 :(得分:0)

它在日志中:

Caused by: org.osgi.framework.BundleException: Duplicate import: javax.servlet.jsp

可能会遇到Karaf / Pax URL WAR中的错误。

在您的情况下,最好创建一个WAB,它仍然可以部署到tomcat服务器。

编辑:

作为额外问题的答案,还要看一下Pax Web提供的样本,特别是这个one

摘自POM:

           <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <supportedProjectTypes>
                    <supportedProjectType>jar</supportedProjectType>
                    <supportedProjectType>bundle</supportedProjectType>
                    <supportedProjectType>war</supportedProjectType>
                </supportedProjectTypes>
                <instructions>
                    <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
                    <Bundle-Version>${project.version}</Bundle-Version>
                    <Import-Package>
                        org.springframework.osgi.web.context.support,
                        org.springframework.web.servlet.view,
                        org.springframework.web.servlet,
                        *; resolution:=optional
                    </Import-Package>
                    <Export-Package>org.ops4j.pax.web.samples.spring.*,!*</Export-Package>
                    <Bundle-Classpath>
                        WEB-INF/classes
                    </Bundle-Classpath>
                    <Web-ContextPath>war-spring</Web-ContextPath>
                    <Embed-Dependency>*; artifactId=!org.osgi.compendium; scope=compile; type=!pom; inline=true</Embed-Dependency>
                    <Embed-Transitive>true</Embed-Transitive>
                    <_removeheaders>
                        Include-Resource,
                        Private-Package,
                        Embed-Dependency,
                        Embed-Transitive,
                        Ignore-Package
                    </_removeheaders>
                </instructions>
            </configuration>
            <executions>
                <execution>
                    <id>generate-manifest</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>manifest</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                </archive>
            </configuration>
        </plugin>