2014-10-02 91 views
0

我已准备好部署项目,因此我需要创建可执行的jar以进行分发。阅读网上现在我想clean and build我的项目(ProjectMaven)后,它是一个Maven项目具有相关性(上Netbeans 8使用Netbeans清理并构建Maven项目 - 编译失败

我的项目对使用Maven

之后另一个项目,我已经创建了一个依赖阅读thisthis答案我做了我的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.dwnz.project</groupId> 
    <artifactId>ProjectMaven</artifactId> 
    <name>DwnzProject</name> 
    <version>1.0-SNAPSHOT</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> 

    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <version>2.2</version> 
      <!-- nothing here --> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.2-beta-4</version> 
      <configuration> 
       <descriptorRefs> 
       <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 
       <archive> 
       <manifest> 
        <mainClass>view.MainFrame</mainClass> 
       </manifest> 
       </archive> 
      </configuration> 
      <executions> 
       <execution> 
       <phase>package</phase> 
       <goals> 
        <goal>single</goal> 
       </goals> 
       </execution> 
      </executions> 
      </plugin> 
      <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
      </plugin> 
    </plugins> 
    </build> 

    <dependencies> 
     <dependency> 
      <groupId>com.googlecode.jcsv</groupId> 
      <artifactId>jcsv</artifactId> 
      <version>1.4.0</version> 
     </dependency> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>5.1.24</version> 
     </dependency> 
     <dependency> 
      <groupId>com.dazito.retro.eventbus</groupId> 
      <artifactId>RetroEventBusMaven</artifactId> 
      <version>1.0-SNAPSHOT</version> 
     </dependency> 
     <dependency> 
      <groupId>org.eclipse.persistence</groupId> 
      <artifactId>eclipselink</artifactId> 
      <version>2.5.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.eclipse.persistence</groupId> 
      <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId> 
      <version>2.5.1</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-entitymanager</artifactId> 
      <version>4.3.6.Final</version> 
     </dependency> 

    </dependencies> 
</project> 

com.dazito.retro.eventbus是我的其他Maven项目我创建了这个项目依赖。

这是Maven在我的项目上按Clean and Build创建的输出(ProjectMaven)。

Compiling 48 source files to C:\Users\Dwnz\Documents\NetBeansProjects\ProjectMaven\target\classes 
------------------------------------------------------------- 
COMPILATION ERROR : 
------------------------------------------------------------- 
view/MainFrame.java:[9,32] error: cannot find symbol 
view/MainFrame.java:[10,49] error: package com.dazito.retro.eventbus.buses.singletons does not exist 
api/CallsToGUI.java:[7,32] error: cannot find symbol 
view/toolbar/ToolBar.java:[9,32] error: cannot find symbol 
view/toolbar/ToolBar.java:[10,49] error: package com.dazito.retro.eventbus.buses.singletons does not exist 
view/menu/ExportTableDialog.java:[9,32] error: cannot find symbol 
view/menu/ExportTableDialog.java:[10,49] error: package com.dazito.retro.eventbus.buses.singletons does not exist 
view/toolbar/AskPasswordDialog.java:[9,32] error: cannot find symbol 
view/toolbar/AskPasswordDialog.java:[10,49] error: package com.dazito.retro.eventbus.buses.singletons does not exist 
view/menu/ImportTableDialog.java:[7,32] error: cannot find symbol 
view/menu/ImportTableDialog.java:[8,49] error: package com.dazito.retro.eventbus.buses.singletons does not exist 
view/MainFrame.java:[107,18] error: cannot find symbol 
view/rightPanel/RightTable.java:[7,32] error: cannot find symbol 
view/rightPanel/RightTable.java:[8,49] error: package com.dazito.retro.eventbus.buses.singletons does not exist 
view/toolbar/ToolBar.java:[34,18] error: cannot find symbol 
view/menu/ExportTableDialog.java:[46,18] error: cannot find symbol 
view/toolbar/AskPasswordDialog.java:[52,12] error: cannot find symbol 
view/menu/ImportTableDialog.java:[36,18] error: cannot find symbol 
view/rightPanel/RightTable.java:[40,18] error: cannot find symbol 
view/actionlisteners/ImportResultsActionListener.java:[10,32] error: cannot find symbol 
view/actionlisteners/ImportResultsActionListener.java:[11,49] error: package com.dazito.retro.eventbus.buses.singletons does not exist 
21 errors 
------------------------------------------------------------- 
------------------------------------------------------------------------ 
BUILD FAILURE 
------------------------------------------------------------------------ 
Total time: 4.311s 
Finished at: Thu Oct 02 07:32:54 BST 2014 
Final Memory: 30M/116M 
------------------------------------------------------------------------ 
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project ProjectMaven: Compilation failure: Compilation failure: 
view/MainFrame.java:[9,32] error: cannot find symbol 
view/MainFrame.java:[10,49] error: package com.dazito.retro.eventbus.buses.singletons does not exist 
api/CallsToGUI.java:[7,32] error: cannot find symbol 
view/toolbar/ToolBar.java:[9,32] error: cannot find symbol 
view/toolbar/ToolBar.java:[10,49] error: package com.dazito.retro.eventbus.buses.singletons does not exist 
view/menu/ExportTableDialog.java:[9,32] error: cannot find symbol 
view/menu/ExportTableDialog.java:[10,49] error: package com.dazito.retro.eventbus.buses.singletons does not exist 
view/toolbar/AskPasswordDialog.java:[9,32] error: cannot find symbol 
view/toolbar/AskPasswordDialog.java:[10,49] error: package com.dazito.retro.eventbus.buses.singletons does not exist 
view/menu/ImportTableDialog.java:[7,32] error: cannot find symbol 
view/menu/ImportTableDialog.java:[8,49] error: package com.dazito.retro.eventbus.buses.singletons does not exist 
view/MainFrame.java:[107,18] error: cannot find symbol 
view/rightPanel/RightTable.java:[7,32] error: cannot find symbol 
view/rightPanel/RightTable.java:[8,49] error: package com.dazito.retro.eventbus.buses.singletons does not exist 
view/toolbar/ToolBar.java:[34,18] error: cannot find symbol 
view/menu/ExportTableDialog.java:[46,18] error: cannot find symbol 
view/toolbar/AskPasswordDialog.java:[52,12] error: cannot find symbol 
view/menu/ImportTableDialog.java:[36,18] error: cannot find symbol 
view/rightPanel/RightTable.java:[40,18] error: cannot find symbol 
view/actionlisteners/ImportResultsActionListener.java:[10,32] error: cannot find symbol 
view/actionlisteners/ImportResultsActionListener.java:[11,49] error: package com.dazito.retro.eventbus.buses.singletons does not exist 
-> [Help 1] 

To see the full stack trace of the errors, re-run Maven with the -e switch. 
Re-run Maven using the -X switch to enable full debug logging. 

For more information about the errors and possible solutions, please read the following articles: 
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 

我在做什么错?我怎样才能解决这个问题,以便我可以清理和构建项目? 该项目没有编译错误,并在netbeans内按下运行按钮时执行罚款。

+0

貌似这个'com.dazito.retro.eventbus .buses.singletons' cass找不到。让它不会拼写错误,并且相关的jar文件在你的类路径 – Jens 2014-10-02 06:44:59

+0

中,你需要在build pom中定义它,这意味着你的项目必须由本地文件夹路径定义或者在maven repo中定义,以便构建其他应用程序取决于它 – AntJavaDev 2014-10-02 06:51:18

回答

1

我不太了解这个插件,但有可能你想要考虑。

而不是汇编插件,使用阴影插件。 http://maven.apache.org/plugins/maven-shade-plugin/

  <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-shade-plugin</artifactId> 
       <version>2.2</version> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>shade</goal> 
         </goals> 
         <configuration> 
          <createDependencyReducedPom>false</createDependencyReducedPom> 
          <filters> 
           <filter> 
            <artifact>*:*</artifact> 
            <excludes> 
             <exclude>META-INF/*.SF</exclude> 
             <exclude>META-INF/*.DSA</exclude> 
             <exclude>META-INF/*.RSA</exclude> 
             <exclude>.settings/**</exclude> 
             <exclude>*.classpath</exclude> 
             <exclude>*.project</exclude> 
             <exclude>*.txt</exclude> 
            </excludes> 
           </filter> 
          </filters> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

并创建一个完整的.exe包括全部或.exe其推出的所有一个.jar,使用launch4j插件https://github.com/lukaszlenart/launch4j-maven-plugin

  <plugin> 
       <groupId>com.akathist.maven.plugins.launch4j</groupId> 
       <artifactId>launch4j-maven-plugin</artifactId> 
       <version>1.5.2</version> 
       <executions> 
        <execution> 
         <id>l4j-gui</id> 
         <phase>package</phase> 
         <goals> 
          <goal>launch4j</goal> 
         </goals> 
         <configuration> 
          <headerType>gui</headerType> 
          <outfile>target/Project.exe</outfile> 
          <jar>target/${project.artifactId}-${project.version}.jar</jar> 
          <!-- if <dontWrapJar>true</dontWrapJar> change to this conf <jar>${project.artifactId}-${project.version}.jar</jar> --> 
          <dontWrapJar>false</dontWrapJar> 
          <errTitle>Error in launch4j plugin</errTitle> 
          <classPath> 
           <mainClass>path.Main</mainClass> 
          </classPath> 
          <icon>Project.ico</icon> 
          <jre> 
           <minVersion>1.5.0</minVersion> 
           <maxVersion>1.6.0</maxVersion> 
           <initialHeapSize>512</initialHeapSize> 
           <maxHeapSize>1024</maxHeapSize> 
          </jre> 
          <versionInfo> 
           <fileVersion>1.0.0.0</fileVersion> 
           <txtFileVersion>1.0.0.0</txtFileVersion> 
           <fileDescription>des</fileDescription> 
           <copyright>Copyright (c) 2014 </copyright> 
           <companyName>comp</companyName> 
           <productVersion>3.0.0.0</productVersion> 
           <txtProductVersion>${project.version}</txtProductVersion> 
           <productName>Project</productName> 
           <internalName>Project</internalName> 
           <originalFilename>Project.exe</originalFilename> 
          </versionInfo> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
+1

哇,这太棒了!这就像一颗子弹杀死两只鸟。谢谢!现在唯一的问题是,双击生成的.exe文件时什么都不会发生。用命令行也没有任何反应,没有输出产生。你碰巧知道为什么? – dazito 2014-10-02 07:11:18

+0

我发现问题出在我应用程序内部的图像上,有些东西没有正确加载它们。我得到这个异常:'无法加载图标:/images/view-refresh.png 线程“main”java.lang.NullPointerException'中的异常。如果我删除它的图片加载就好了。谢谢! – dazito 2014-10-02 07:44:23