Tworzenia jara w intelij - z IDE program działa, z jar nie - maven project

0

Witam,
Mam projekt mavenowy jest to java SE + javaFX + JPA/Hibernate. Z poziomu intelij daję Run(Shift + F10) wszystko działa tak jak powinno.
Teraz opiszę jak tworzę jara.

  1. Klikam File.
  2. Klikam Project Structure.
  3. Wybieram airfacts.
  4. Klikam zielonego plusa.
  5. Klikam Jar.
  6. Wybieram From mudules nazwa mojego projektu with dependecies.
  7. Wybieram Main Class.
  8. Jar files from libraries ustawiam na: extract to the target JAR. Klikam ok.
  9. Tak.PNG.
  10. Klikam Apply/OK.
  11. Klikam Build Artifact daje build.

Jar się wygenerował, klikam dwukrotnie w niego, ale program się nie włącza.

Druga próba:

  1. Klikam File.
  2. Klikam Project Structure.
  3. Wybieram airfacts.
  4. Klikam zielonego plusa.
  5. Klikam JavaFx Applications From mudule TaskManager(nazwa mojego projektu).
    6.Wybieram Main Class.
    2.PNG.

Teraz jar się odpala:
3.PNG

Problem jest taki, że po wciśnięciu przycisku zaloguj nic się nie dzieje, a jak odpalałem program z IDE to wszystko działało.

pom.xml wygląda tak:

<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.my.app</groupId>
    <artifactId>TaskManager</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <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>
    <dependencies>

        <dependency>
            <groupId>commons-configuration</groupId>
            <artifactId>commons-configuration</artifactId>
            <version>1.10</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.34</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.8.Final</version>
        </dependency>

        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>

        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>itextpdf</artifactId>
            <version>5.5.5</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.1.3.Final</version>
        </dependency>

        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>el-impl</artifactId>
            <version>2.2</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>javax.mail-api</artifactId>
            <version>1.5.3</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.5.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
        </dependency>
        <dependency>
            <groupId>com.akathist.maven.plugins.launch4j</groupId>
            <artifactId>launch4j-maven-plugin</artifactId>
            <version>1.7.7</version>
        </dependency>

    </dependencies>
</project>
 

Gdzie szukać błędu, skoro z IDE wszystko działa? Hibernate ustawione na hibernate.hbm2ddl.auto=update, ale to raczej nie w tym problem.

1

Spróbuj na maven onejar plugin, ja korzystam z tego jak robię jar dla JavaSE.

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    
    <build>
        <plugins>
            
            <plugin>
                <groupId>org.dstovall</groupId>
                <artifactId>onejar-maven-plugin</artifactId>
                <version>1.4.4</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>one-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>pl.package.main.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>                
            </plugin>

        </plugins>
            
    </build>
    <pluginRepositories>
        <pluginRepository>
            <id>onejar-maven-plugin.googlecode.com</id>
            <a href="http://onejar-maven-plugin.googlecode.com/svn/mavenrepo">http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</a>
        </pluginRepository>
   </pluginRepositories>

Po wykonaniu mvn package znajdziesz w target plik z sufiksem .one-jar.jar.

0

@margor90 dodałem do poma. Tylko nie bardzo nie bardzo wiem jak wykonać to polecenie. Mavena mam wbudowanego w intelij.

Po kliknięciu w onejar-one-jar po prawej stronie:

"D:\Program Files\Java\jdk1.8.0_40\bin\java" "-Dmaven.home=D:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1.1\plugins\maven\lib\maven3" "-Dclassworlds.conf=D:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1.1\plugins\maven\lib\maven3\bin\m2.conf" -Didea.launcher.port=7535 "-Didea.launcher.bin.path=D:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1.1\bin" -Dfile.encoding=windows-1250 -classpath "D:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1.1\plugins\maven\lib\maven3\boot\plexus-classworlds-2.4.jar;D:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1.1\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=14.1.1 org.dstovall:onejar-maven-plugin:1.4.4:one-jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TaskManager 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- onejar-maven-plugin:1.4.4:one-jar (default-cli) @ TaskManager ---
[INFO] Using One-Jar to create a single-file distribution
[INFO] Implementation Version: 0.0.1-SNAPSHOT
[INFO] Using One-Jar version: 0.97
[INFO] More info on One-Jar: http://one-jar.sourceforge.net/
[INFO] License for One-Jar: http://one-jar.sourceforge.net/one-jar-license.txt
[INFO] One-Jar file: D:\Documents\IdeaProjects\inzL1G3\TaskManager\target\TaskManager-0.0.1-SNAPSHOT.one-jar.jar
[ERROR]
java.io.FileNotFoundException: D:\Documents\IdeaProjects\inzL1G3\TaskManager\target\TaskManager-0.0.1-SNAPSHOT.jar (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at org.dstovall.OneJarMojo.addToZip(OneJarMojo.java:266)
at org.dstovall.OneJarMojo.execute(OneJarMojo.java:160)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.019s
[INFO] Finished at: Sun Jun 07 1147 CEST 2015
[INFO] Final Memory: 6M/141M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.dstovall:onejar-maven-plugin:1.4.4:one-jar (default-cli) on project TaskManager: One-jar Mojo failed. D:\Documents\IdeaProjects\inzL1G3\TaskManager\target\TaskManager-0.0.1-SNAPSHOT.jar (The system cannot find the file specified) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Process finished with exit code 1zle1.PNG

zle2.PNG

0

Aby Windows zobaczył komendę mvn musisz odpowiednio skonfigurować zmienne środowiskowe:
http://crunchify.com/how-to-setupinstall-maven-classpath-variable-on-windows-7/

1 użytkowników online, w tym zalogowanych: 0, gości: 1