Web Services JAVA Web服务

zhte4eai  于 2022-11-15  发布在  Java
关注(0)|答案(1)|浏览(251)

我有一个java web服务,我尝试使用eclipse创建jar文件。我通过插入goal=package创建jar文件,但是创建的jar文件无法使用批处理文件星星。顺便说一下,项目在eclipse中本地运行,并连接到数据库。有人知道我在创建jar文件时遗漏了什么吗?下面是我的pom.xml:

<?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.galaksiya</groupId>
        <artifactId>SectraXDSIIntegration</artifactId>
        <version>2.1.8</version>
        <profiles>
            <profile>
                <id>production</id>
                <build>
                    <resources>
                        <resource>
                            <directory>web/app</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                            <targetPath>resources</targetPath>
                        </resource>
                        <resource>
                            <directory>src/main/resources/templates</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                            <targetPath>templates</targetPath>
                        </resource>
                        <resource>
                            <directory>production</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                        </resource>
                    </resources>
                    <plugins>
                        <plugin>
                            <artifactId>maven-jar-plugin</artifactId>
                            <configuration>
                                <archive>
                                    <manifest>
                                        <addClasspath>true</addClasspath>
                                        <classpathPrefix>lib</classpathPrefix>
                                        <mainClass>com.galaksiya.sectra.integration.main.Runner</mainClass>
                                    </manifest>
                                </archive>
                            </configuration>
                        </plugin>
                        <plugin>
                            <artifactId>maven-dependency-plugin</artifactId>
                            <executions>
                                <execution>
                                    <id>copy-dependencies</id>
                                    <phase>prepare-package</phase>
                                    <goals>
                                        <goal>copy-dependencies</goal>
                                    </goals>
                                    <configuration>
                                        <outputDirectory>${project.build.directory}/lib</outputDirectory>
                                        <overWriteSnapshots>true</overWriteSnapshots>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
            <resources>
                <resource>
                    <directory>web/app</directory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                    <targetPath>resources</targetPath>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>**/*</include>
                    </includes>
                </resource>
            </resources>
            
        </build>
        <repositories>
            <repository>
                <id>www.dcm4che.org</id>
                <name>dcm4che Repository</name>
                <url>http://www.dcm4che.org/maven2</url>
            </repository>
            <repository>
                <id>galaksiya</id>
                <url>http://maven.galaksiya.net</url>
            </repository>
            <repository>
                <id>gluu</id>
                <name>Gluu repository</name>
                <url>http://ox.gluu.org/maven</url>
            </repository>
        </repositories>
        <dependencies>
            <dependency>
                <groupId>com.sun.media</groupId>
                <artifactId>jai_imageio</artifactId>
                <version>1.2-pre-dr-b04</version>
                <scope>runtime</scope>
            </dependency>
            <!-- <dependency> -->
            <!-- <groupId>org.dcm4che.tool</groupId> -->
            <!-- <artifactId>dcm4che-tool-common</artifactId> -->
            <!-- <version>3.3.7</version> -->
            <!-- <scope>compile</scope> -->
            <!-- </dependency> -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.7.25</version>
            </dependency>
            <dependency>
                <groupId>com.galaksiya</groupId>
                <artifactId>DatabaseConnector</artifactId>
                <version>2.1.2</version>
            </dependency>
            <dependency>
                <groupId>com.galaksiya</groupId>
                <artifactId>MakeKOS</artifactId>
                <version>1.9.0</version>
            </dependency>
            <dependency>
                <groupId>com.galaksiya</groupId>
                <artifactId>SendKOS</artifactId>
                <version>1.5.5</version>
                <exclusions>
                    <exclusion>
                        <groupId>javax.servlet</groupId>
                        <artifactId>servlet-api</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-server</artifactId>
                <version>9.2.3.v20140905</version>
            </dependency>
            <dependency>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-servlet</artifactId>
                <version>9.2.3.v20140905</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-client -->
            <dependency>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-client</artifactId>
                <version>9.2.3.v20140905</version>
            </dependency>
            <dependency>
                <groupId>org.glassfish.jersey.containers</groupId>
                <artifactId>jersey-container-servlet-core</artifactId>
                <version>2.25</version>
            </dependency>
            <dependency>
                <groupId>org.glassfish.jersey.test-framework.providers</groupId>
                <artifactId>jersey-test-framework-provider-jetty</artifactId>
                <version>2.25</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-all</artifactId>
                <version>1.10.19</version>
            </dependency>
            <dependency>
                <groupId>org.powermock</groupId>
                <artifactId>powermock-api-mockito</artifactId>
                <version>1.6.6</version>
            </dependency>
            <dependency>
                <groupId>org.powermock</groupId>
                <artifactId>powermock-module-junit4</artifactId>
                <version>1.6.6</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.microsoft.sqlserver</groupId>
                <artifactId>mssql-jdbc</artifactId>
                <version>6.1.4.jre8-preview</version>
            </dependency>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.8.2</version>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>3.1.0</version>
            </dependency>
            <dependency>
                <groupId>org.glassfish.jersey.media</groupId>
                <artifactId>jersey-media-multipart</artifactId>
                <version>2.25</version>
            </dependency>
            <dependency>
                <groupId>com.galaksiya</groupId>
                <artifactId>GLogger</artifactId>
                <version>2.0.4</version>
            </dependency>
            <dependency>
                <groupId>com.galaksiya</groupId>
                <artifactId>Emailer</artifactId>
                <version>1.0.3</version>
                <exclusions>
                    <exclusion>
                        <groupId>com.galaksiya</groupId>
                        <artifactId>GLogger</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
             <dependency>
                <groupId>com.galaksiya.sectra</groupId>
                <artifactId>Middleware</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>com.galaksiya.sectra</groupId>
                <artifactId>Middleware</artifactId>
                <version>1.0-SNAPSHOT</version>
                <type>test-jar</type>
            </dependency>
            <dependency>
                <groupId>dcm4che.tool</groupId>
                <artifactId>dcm4che-tool-dcmsnd</artifactId>
                <version>2.0.29</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </project>
aelbi1ox

aelbi1ox1#

要创建一个可执行的jar文件,你需要在maven-jar-plugin清单配置中添加一个<mainClass>元素。你的pom.xml已经包含了这样的配置,但是它被放置在一个名为production的配置文件中。因此,除非你激活生产配置文件,否则它将被忽略:

mvn package -Pproduction

在此之后,您应该能够启动jar文件,如下所示:

java -jar target/SectraXDSIIntegration-2.1.8.jar

有关配置文件的更多信息,您可以查看the relevant Maven documentation,有关如何配置maven-jar-plugin的更多信息,您可以查看its documentation

相关问题