Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法使用maven项目创建可运行的jar文件_Java_Spring_Maven - Fatal编程技术网

Java 无法使用maven项目创建可运行的jar文件

Java 无法使用maven项目创建可运行的jar文件,java,spring,maven,Java,Spring,Maven,我从.NET到java的转换遇到了很多问题,尤其是使用SPring工具套件。我创建了一个简单的maven项目,因为每个人都告诉我这是最好的方式,因为maven会下载所有需要的库并对它们进行打包。在无休止的错误和尝试修复之后,我让项目开始工作,并在Spring中以调试模式运行它。试图创建一个可运行的jar,这就是问题的根源。第一个jar无法处理此错误: Exception in thread "main" java.lang.reflect.InvocationTargetException

我从.NET到java的转换遇到了很多问题,尤其是使用SPring工具套件。我创建了一个简单的maven项目,因为每个人都告诉我这是最好的方式,因为maven会下载所有需要的库并对它们进行打包。在无休止的错误和尝试修复之后,我让项目开始工作,并在Spring中以调试模式运行它。试图创建一个可运行的jar,这就是问题的根源。第一个jar无法处理此错误:

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
    Caused by: org.apache.hadoop.hbase.client.NoServerForRegionException: 
    Unable to find region for  after 35 tries.
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.
    locateRegionInMeta(ConnectionManager.java:1251)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.
     locateRegion(ConnectionManager.java:1128)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.
    locateRegion(ConnectionManager.java:1111)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegion
    (ConnectionManager.java:1070)
    at org.apache.hadoop.hbase.client.HTable.finishSetup(HTable.java:347)
    at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:201)
    at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:159)
    at com.boardreader.hbase.HBaseMain.main(HBaseMain.java:148)
    ... 5 more
现在真的很沮丧。已从pom文件中删除条目,重建和清理无效。调试或作为java应用程序运行不起作用。关闭Spring,然后重新打开并清理项目,最后在调试模式下工作。我需要让它工作,以部署到另一台服务器,但为什么这是如此难以完成。尽管微软不断抱怨,但我在部署一个项目时并没有遇到任何问题

编辑:

更改插件

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
    <execution>
        <phase>package</phase>
        <goals>
            <goal>shade</goal>
        </goals>
        <configuration>
            <filters>
                <filter>
                    <artifact>*:*</artifact>
                    <excludes>
                        <exclude>META-INF/*.SF</exclude>
                        <exclude>META-INF/*.DSA</exclude>
                        <exclude>META-INF/*.RSA</exclude>
                        <exclude>LICENSE</exclude>
                        <exclude>LICENSE.txt</exclude>
                        <exclude>NOTICE.txt</exclude>
                    </excludes>
                </filter>
            </filters>
            <transformers>
                <transformer  implementation="org.apache.maven.plugins.shade.resource.
                        ManifestResourceTransformer">
                    <mainClass>com.myproject.deduper.HBaseMain</mainClass>
                </transformer>
            </transformers>
        </configuration>
    </execution>
</executions>
 </plugin>


将JAVA_HOME设置为指向jdk(而非jre)

添加这个插件

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>com.company.Main</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>

org.apache.maven.plugins
maven jar插件
真的
com.company.Main
配置eclipse以使用jdk:首先您的计算机上必须有jdk,如果没有,请键入google“download jdk”并下载它
然后转到如下图所示的设置,单击添加…,然后选择Standart VM,单击下一步, 并指定jdk的路径。

切换到。它比汇编插件更易于使用和更好地支持。另外,它不需要您运行单独的maven目标。它钩住包并安装。这应该可以为您做到:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                            <exclude>LICENSE</exclude>
                            <exclude>LICENSE.txt</exclude>
                            <exclude>NOTICE.txt</exclude>
                        </excludes>
                    </filter>
                </filters>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>com.x.y.z.Test</mainClass>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
</plugin>

org.apache.maven.plugins
maven阴影插件
包裹
阴凉处
*:*
META-INF/*.SF
META-INF/*.DSA
META-INF/*.RSA
许可证
LICENSE.txt
NOTICE.txt
com.x.y.z.测试

您缺少tools.jar,它是jdk的一部分,所以您必须使用jreDo,我需要更改上面的设置吗?在第二张图片中,在已安装的JREsIts下没有添加jdk的选项,JRE说,但是您应该在那里指定jdk的路径,请参见图片
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.338 s
[INFO] Finished at: 2014-12-08T09:54:30-05:00
[INFO] Final Memory: 13M/244M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:
compile   (default-compile) on project Hbase-t: Fatal error compiling: tools.jar not 
found: C:\Program Files\Java\jre7\..\lib\tools.jar -> [Help 1]
[ERROR]
JAVA_HOME=C:\jdk1.7.0_71
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>com.company.Main</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                            <exclude>LICENSE</exclude>
                            <exclude>LICENSE.txt</exclude>
                            <exclude>NOTICE.txt</exclude>
                        </excludes>
                    </filter>
                </filters>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>com.x.y.z.Test</mainClass>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
</plugin>