Launching of JAR from Maven Project



  • Project developed Maven Total NetBeans
    Trying to let him down. JAR- team.

    java -cp MyProject-0.1.0.jar ru.com.myproject.Main

    where

    ru.com.myproject. Main

    There's a major class, because I've pointed out the main class.
    Self-process of the Self-Governing ProjectIt's still not in the manifest. ♪ ♪

    I'm making a mistake:

    Exception in thread "main" java.lang.NoClassDefFoundError: com/thetransactioncompany/jsonrpc2/JSONRPC2Parser
            at ru.com.myproject.<clinit>(Main.java:28)
    Caused by: java.lang.ClassNotFoundException: com.thetransactioncompany.jsonrpc2.JSONRPC2Parser
            at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
            ... 1 more
    

    Contained file pom:

    <?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>ru.com</groupId>
        <artifactId>MyProject</artifactId>
        <version>0.1.0</version>
        <packaging>jar</packaging>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.7</maven.compiler.source>
            <maven.compiler.target>1.7</maven.compiler.target>
        </properties>
        <dependencies>
            <dependency>
                <groupId>com.thetransactioncompany</groupId>
                <artifactId>jsonrpc2-base</artifactId>
                <version>1.38</version>
            </dependency>
            <dependency>
                <groupId>commons-lang</groupId>
                <artifactId>commons-lang</artifactId>
                <version>2.1</version>
                <type>jar</type>
            </dependency>
            <dependency>
                <groupId>org.apache.maven.surefire</groupId>
                <artifactId>maven-surefire-common</artifactId>
                <version>2.17</version>
                <type>jar</type>
            </dependency>
        </dependencies>
    </project>
    

    So how do we get the project together? Maven Total NetBeans So it's right. manifest- File, was the master class and dependence correct?

    Or how to launch the project. Maven ?



  • Java cannot find dependence, particularly jsonrpc2. They may be added to the CLASSPATH or packed in one jar. The first can be done both manually and through maven-dependency-plugin:

    <project>
        ...
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.10</version>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/lib</outputDirectory>
                                <overWriteReleases>false</overWriteReleases>
                                <overWriteSnapshots>false</overWriteSnapshots>
                                <overWriteIfNewer>true</overWriteIfNewer>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
        ...
    </project>
    

    Two with help maven-assembly-plugin:

    <project>
        ...
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>fully.qualified.MainClass</mainClass>
                            </manifest>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        ...
    </project>
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2