0

I just faced problem I can not get rid off, like in title, when I build .jar from maven project using netbeans it just do not open outside of IDE. Using run button in IDE runs application perfectly and without problems, but builded .jar's just do not open. Other .jar's from other projects works normally, it is first time I am building something with maven so I think the problem is there.

This is my pom file, hope the problem is somewhere here:

<?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.bbzoftware</groupId>
    <artifactId>HDiSED</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <springframework.version>4.0.6.RELEASE</springframework.version>
        <hibernate.version>4.3.5.Final</hibernate.version>
        <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>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.31</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.9</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>itextpdf</artifactId>
            <version>5.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.7.2</version>
        </dependency> 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-shade-plugin</artifactId>
              <version>2.3</version>
              <executions>
                <execution>
                  <phase>package</phase>
                  <goals>
                    <goal>shade</goal>
                  </goals>
                  <configuration>
                    <transformers>
                      <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <manifestEntries>
                          <Main-Class>com.bbzoftware.hdised.controller.Main</Main-Class>
                          <Build-Number>123</Build-Number>
                        </manifestEntries>
                      </transformer>
                    </transformers>
                  </configuration>
                </execution>
              </executions>
            </plugin>
        </plugins>
    </build>
</project>
Damian Lesniak
  • 462
  • 2
  • 5
  • 19
  • 1
    What do you mean by open here? Execute? Or open with a zip utility? – JamesB Sep 25 '14 at 13:58
  • Execute by double click or with console. – Damian Lesniak Sep 25 '14 at 13:59
  • You may need to use a plugin like maven-depedency-plugin to copy the maven dependencies to a lib directory, or package them in the jar. You woudl also need to set a ClassPath entry for each dependency in the manfiest. You can check if the dependencies are the issue by launching the jar from a shell (cmd, or terminal) using java -jar MyJarsName.jar. If you provide that stack trace, it would be easier to tell what your problem is. Just redirect the output with >> in cmd or | in terminal to some text file. – Mark W Sep 25 '14 at 14:11
  • More probably, maven did not put a `MANIFEST.MF` in the `META-INF` directory of the jar. Sadly enough, but the default plugins generate a *library* jar, not an *executable* one - and I'm not good enough at maven to give you a solution :-( – Serge Ballesta Sep 25 '14 at 14:20
  • You need to configure your pom to generate an executable jar. Check [this](http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven) question, it tries to accomplish the same. – Keshav Pandey May 07 '16 at 02:07

1 Answers1

0

Locate your jar file and try opening it with for example 7zip. Jar file is just an archive file.

gogic1
  • 111
  • 1
  • 10