我想将我的项目打包在一个可执行的JAR中进行分发.
如何将所有依赖JAR的Maven项目打包到我的输出JAR中?
我的代码在一个JAR文件中运行,比如说foo.jar,我需要在代码中知道运行foo.jar的文件夹.
所以,如果foo.jar在C:\FOO\
,我想要获得该路径,无论我当前的工作目录是什么.
我的java程序打包在一个jar文件中,并使用外部jar库,bouncy castle.我的代码编译得很好,但是运行jar会导致以下错误:
线程"main"中的异常java.lang.SecurityException:Manifest主要属性的签名文件摘要无效
我用谷歌搜索了一个多小时寻找解释,发现很少有价值.如果有人以前看过这个错误并且可以提供一些帮助,我将不得不承担责任.
我有一个名为helloworld.jar的JAR文件.为了运行它,我在命令行窗口中执行以下命令:
java -jar helloworld.jar
Run Code Online (Sandbox Code Playgroud)
这工作正常,但如何通过双击执行它?我需要安装任何软件吗?
Execution default of goal
org.springframework.boot:spring-boot-maven-plugin:1.0.1.RELEASE:repackage
failed:
Unable to find a single main class from the following candidates
Run Code Online (Sandbox Code Playgroud)
我的项目有多个带有main
方法的类.我如何告诉Spring Boot Maven插件它应该用作哪个类作为主类?
我有一个包含4个类的JAR,每个类都有Main方法.我希望能够根据需要运行其中的每一个.我试图从Linux机器上的命令行运行它.
E.g. The name of my JAR is MyJar.jar
Run Code Online (Sandbox Code Playgroud)
它具有主类的目录结构,如下所示:
com/mycomp/myproj/dir1/MainClass1.class
com/mycomp/myproj/dir2/MainClass2.class
com/mycomp/myproj/dir3/MainClass3.class
com/mycomp/myproj/dir4/MainClass4.class
Run Code Online (Sandbox Code Playgroud)
我知道我可以在我的Manifest文件中指定一个类作为main.但有没有什么方法可以在命令行上指定一些参数来运行我希望运行的任何类?
我试过这个:
jar cfe MyJar.jar com.mycomp.myproj.dir2.MainClass2 com/mycomp/myproj/dir2/MainClass2.class /home/myhome/datasource.properties /home/myhome/input.txt
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误:
com/mycomp/myproj/dir2/MainClass2.class : no such file or directory
Run Code Online (Sandbox Code Playgroud)
(在上面的命令中,'/ home/myhome/datasource.properties'和'/home/myhome/input.txt'是命令行参数).
我正在尝试使用maven为一个名为"logmanager"的小型家庭项目生成一个可执行jar,就像这样:
我将那里显示的代码段添加到pom.xml中,然后运行mvn assembly:assembly.它在logmanager/target中生成两个jar文件:logmanager-0.1.0.jar和logmanager-0.1.0-jar-with-dependencies.jar.当我双击第一个jar时出现错误:
Could not find the main class: com.gorkwobble.logmanager.LogManager. Program will exit.
Run Code Online (Sandbox Code Playgroud)
当我双击jar-with-dependencies.jar时出现稍微不同的错误:
Failed to load Main-Class manifest attribute from: C:\EclipseProjects\logmanager\target\logmanager-0.1.0-jar-with-dependencies.jar
Run Code Online (Sandbox Code Playgroud)
我复制并粘贴了路径和类名,并检查了POM中的拼写.我的主要类从eclipse启动配置启动.有人可以帮我弄清楚为什么我的jar文件不会运行?另外,为什么有两个罐开始?如果您需要更多信息,请与我们联系.
这是完整的pom.xml
,供参考:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gorkwobble</groupId>
<artifactId>logmanager</artifactId>
<name>LogManager</name>
<version>0.1.0</version>
<description>Systematically renames specified log files on a scheduled basis. Designed to help manage MUSHClient logging and prevent long, continuous log files.</description>
<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>com.gorkwobble.logmanager.LogManager</mainClass> …
Run Code Online (Sandbox Code Playgroud) 我想在不使用IDE的情况下执行我的程序.我已经创建了一个jar文件和一个exectuable jar文件.当我双击exe jar文件时,没有任何反应,当我尝试在cmd中使用该命令时,它给了我:
Error: Unable to access jarfile <path>
Run Code Online (Sandbox Code Playgroud)
我使用命令: java -jar Calculator.jar
我是如何创建jar的:
我写了几个名为A.jar,B.jar的简单java应用程序.现在我想编写一个GUI java程序,以便用户可以按下按钮A执行A.jar,按钮B执行B.jar.我也想在GUI程序中输出运行时进程细节.有什么建议吗?
我需要在服务器中运行一个java jar,以便在两个应用程序之间进行通信.我编写了两个shell脚本来运行它,但是一旦我启动该脚本,我就无法关闭/终止该过程.如果我按ctrl+ C或关闭控制台,服务器将关闭.任何人都可以帮我如何修改此脚本作为普通服务器运行?
#!/bin/sh
java -jar /web/server.jar
echo $!
#> startupApp.pid
Run Code Online (Sandbox Code Playgroud)