简体   繁体   English

Maven-如何使用可执行jar文件制作项目

[英]maven - how to make a project with executable jar file

I have a maven app and I want to make an executable .jar from it. 我有一个Maven的应用程序,我想打一个可执行.jar从它。 I tried using maven-jar-plugin , but when I run the .jar file made from maven-jar-plugin, it gives an error: Can't find main manifest . 我尝试使用maven-jar-plugin ,但是当我运行由maven-jar-plugin制成的.jar文件时,它给出了一个错误: Can't find main manifest I also tried using maven-assembly-plugin , but it gives an error: 我也尝试使用maven-assembly-plugin ,但是它给出了一个错误:

Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [ http://www.springframework.org/schema/context] Offending resource: class path resource [appContext.xml] 线程“主”中的异常org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置问题:无法为XML模式命名空间找到Spring NamespaceHandler [ http://www.springframework.org/schema/context]令人讨厌的资源:类路径资源[appContext.xml]

I tried using maven-shade-plugin , but it gives the same error with the NamespaceHandler . 我尝试使用maven-shade-plugin ,但与NamespaceHandler给出了相同的错误。 I looked everywhere and I can't seem to find the solution to the problem. 我四处张望,似乎找不到解决问题的办法。

My app also uses a .jar from a different app, that is added to the classpath. 我的应用程序还使用其他应用程序中的.jar ,该.jar已添加到类路径中。 I also tried putting them in the same directory, but that doesn't work either. 我也尝试将它们放在同一目录中,但这也不起作用。

Parts of my pom.xml file: 我的pom.xml文件的一部分:

         <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <!-- spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
           .
           .
           .
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.0</version>

                <configuration>
                        <tarLongFileMode>posix</tarLongFileMode>

                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>com.escomled.machinelearning.ml.Escomled_Streams_H2O_ML</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>assemble-all</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

My appContext.xml file: 我的appContext.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:hz="http://www.hazelcast.com/schema/spring"
    xmlns:task="http://www.springframework.org/schema/task" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.hazelcast.com/schema/spring http://www.hazelcast.com/schema/spring/hazelcast-spring-3.2.xsd 
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd ">

    <context:annotation-config />
    <context:component-scan base-package="com.escomled" />
    <context:component-scan base-package="com.escomled.*" />
    <import resource="classpath*:config/blackBoard.xml" />
    <task:annotation-driven />

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>file:///home/escomled/escomled_server/config/escomled.properties</value>
            </list>
        </property>
    </bean>

    <bean id="blackboard" class="com.escomled.blackboard.impl.BlackboardImpl">
        <property name="hazelcastInstance" ref="hazelcastClient" />
    </bean>
</beans>

I tried a lot of things and none of them worked, the .jar is not working, so can someone tell me from the beginning how to do it and what am I doing wrong? 我尝试了很多事情,但没有一个起作用, .jar不起作用,所以有人可以从一开始就告诉我该怎么做以及我在做什么错吗? (I will edit my question if you need additional info, just comment) (如果您需要其他信息,我会编辑我的问题,请发表评论)

在使用maven-assembly-plugin时,您是否尝试运行以下命令:

mvn assembly:assembly -DdescriptorId=jar-with-dependencies package

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

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