简体   繁体   中英

JAVA Web-services

I have a java web-service which i try to create the jar file by using eclipse. I create the jar file by inserting goal=package but the created jar file cannot star by using batch file. By the way, the project runs locally in eclipse and connects to the database. Does anyone know what I am missing while creating the jar file. Here is my 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>

To create an executable jar file you need to add a <mainClass> element to the maven-jar-plugin manifest configuration. Your pom.xml already contains such a configuration, but it is placed within a profile called production . As such, it is ignored unless you activate the production profile:

mvn package -Pproduction

After this you should be able to start your jar file as follows:

java -jar target/SectraXDSIIntegration-2.1.8.jar

For more information about profiles you can check out the relevant Maven documentation , and for more information on how to configure the maven-jar-plugin you can check out its documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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