I am trying to creat JAR file through eclipse. I read some of the threads from
Run Code Online (Sandbox Code Playgroud)
stackoverflow以及其他论坛.但没有任何帮助.
我创建了一个像这样的单独的清单文件.
Manifest-Version: 1.0
Main-Class: Main
Class-Path: gnujaxp.jar iText-2.1.5.jar jcalendar.jar jcommon-1.0.16.jar jfreechart-1.0.13.jar jfreechart-1.0.13-experimental.jar jfreechart-1.0.13-swt.jar junit.jar servlet.jar swtgraphics2d.jar tinyos.jar
Run Code Online (Sandbox Code Playgroud)
我把所有这些罐放在同一个项目文件夹中.
导出时我正在导出所有资源(也就是这个jar文件.)
但是当我的应用程序试图加载任何一个包含的jar时,我仍然会收到noclassdeffound错误.
我错在哪里..
提前致谢.
(免责声明:我不是Java程序员,我真的很想不到我在Eclipse中做了什么)
我在Eclipse中删除了一个应用程序,最后我完成并导出为JAR,运行得很好.我没有做任何笔记或发表任何评论.
是时候对项目进行一些更改了,但是我必须重新加载它,因为我的PC已经被擦除所以一些设置等可能已经改变了.
无论如何,它都可以在Eclipse中运行并运行良好.但是当我导出为可运行的JAR,并双击运行应用程序时,它似乎没有执行.
我可以看到有一个javaw运行的实例,但没有窗口出现.没有错误.纳达.
正如我所说,它在Eclipse中运行得非常好.有任何想法吗?
我几乎不知道如何检测发生了什么 - 正如我所说,我不是一个java程序员:-)
我正在尝试从命令行创建一个可执行jar.JAR中的主类具有我已打包到另一个普通JAR文件中的依赖项.
我想将依赖项JAR与可执行JAR打包在一起,以便发送一个JAR文件.
我到目前为止尝试的是以下内容:
依赖项Hello.class文件具有模拟代码:
public class Hello {
public String getHello() {
return "Well hello there!!";
}
}
Run Code Online (Sandbox Code Playgroud)
我使用以下方法将类文件打包到hello.jar中:
jar cvfM hello.jar Hello.class
Run Code Online (Sandbox Code Playgroud)
该hello.jar内容现在是:
hello.jar -+- Hello.class
Run Code Online (Sandbox Code Playgroud)
现在我有主要类与模拟代码:
public class Main {
public static void main(String[] args) {
System.out.println(new Hello().getHello());
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我创建一个清单文件manifest.txt,其中包含以下内容:
Main-Class: Main
Class-Path: hello.jar
Run Code Online (Sandbox Code Playgroud)
我现在使用以下方法创建可执行JAR:
jar cvfm main.jar manifest.txt Main.class hello.jar
Run Code Online (Sandbox Code Playgroud)
该main.jar文件内容是现在:
main.jar -+- Main.class
|
+- hello.jar
|
+- META-INF -+- MANIFEST.MF
Run Code Online (Sandbox Code Playgroud)
使用以下命令运行可执行JAR:
java -jar main.jar
Run Code Online (Sandbox Code Playgroud)
我得到Hello类依赖项的类加载器错误.我知道这是因为类加载器在与main.jar …
我通过以下pom.xml指令为我的Java jar创建一个清单文件:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>parser.BulkParser</mainClass>
<classpathPrefix>dependency/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
这导致生成以下类型的清单:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: shaashis
Build-Jdk: 1.6.0_21
Main-Class: parser.BulkParser
Class-Path: dependency/commons-configuration-1.6.jar dependency/commons-collections-3.2.1.jar dependency/commons-lang-2.4.jar
Run Code Online (Sandbox Code Playgroud)
在这里,我想在Class-Path中添加以下类型的字符串:
Class-Path: conf/ dependency/commons-configuration-1.6.jar dependency/commons-collections-3.2.1.jar dependency/commons-lang-2.4.jar
Run Code Online (Sandbox Code Playgroud)
我怎么能通过我的pom.xml做到这一点?
谢谢
阿希什
我想通过导出在eclipse中创建一个包含引用库的可运行JAR,即jackson.在Eclipse提供导出到可运行的JAR之前,曾经有一个似乎是goto解决方案的胖jar.
从这个问题,第一个选择将是我正在寻找的.由于目前这是一个小项目,所以总是将所有东西放在一起并不是一个问题(而且对我来说更容易,因为我刚开始使用JAR,runnables和jnlp)
当我尝试启动它时,会出现一个警告窗口,说明存在问题并尝试在控制台中找到它(我无法打开它).
如果我删除对这个引用库的任何使用,一切都运行得很好(除了它根本不做我想要的部分).窗口看起来像我设计它的方式,但没有库的功能.
我甚至没有堆栈跟踪来帮助解决问题.我创建了没有任何引用库的其他项目,一切都很好.所以我几乎把它缩小了.
由于我让Eclipse处理导出和所有内容,我不认为你需要清单来查看它是否正常.如果您有任何问题,我将提供您需要的信息.毫无疑问,该项目直接从Eclipse运行.
Eclipse版本:Indigo Service Release 2 Build id:20120216-1857
按照巴克塔的回答编辑
当我这样做时会发生什么,我得到一个自定义的RuntimeException.我在这里有点困惑.这是我的代码的简单解释.我有一个使用引用库(jackson)的实用程序类(UtilityJSON).该实用程序类的构造函数实例化在引用的库中定义的对象,让我们将其称为映射器.UtilityJSON的方法使用'mapper'方法.此时引发异常.为什么我感到困惑的是'mapper'被成功实例化,但使用它的方法会引发异常.如果jar找不到引用的库,它可能无法创建对象'mapper'.但是从Eclipse运行项目一切都很好.运行可执行jar时有没有办法调试?也许在控制台中回应一些东西.
编辑2
我可能发现了错误.我的程序读取项目内文件夹中的*.txt文件.在探索jar的内容时,我看到该文件夹未包含在内,因此异常.所以问题现在变成:我如何包含这个文件夹?它位于项目的根文件夹中.
我正在尝试从 eclipse 制作一个可执行的 jar 文件(使用 MySQL 作为数据库)。
如何制作可执行的jar文件?
我做了一个,但它显示了一些警告并且不起作用。我收到了一个很长的警告列表。这是警告:
JAR export finished with warnings. See details for additional information.
Exported with compile warnings: AngalTask/src/org/isf/accounting/gui/PatientBillEdit.java
Exported with compile warnings: AngalTask/src/org/isf/accounting/gui/BillBrowser.java
Exported with compile warnings: AngalTask/src/org/isf/admission/gui/AdmissionBrowserOld.java
Exported with compile warnings: AngalTask/src/org/isf/admission/gui/AdmittedPatientBrowser.java
Exported with compile warnings: AngalTask/src/org/isf/admission/gui/AdmissionBrowser.java
Exported with compile warnings: AngalTask/src/org/isf/disease/gui/DiseaseEdit.java
Exported with compile warnings: AngalTask/src/org/isf/disease/gui/DiseaseBrowser.java
Exported with compile warnings: AngalTask/src/org/isf/exa/gui/ExamBrowser.java
Exported with compile warnings: AngalTask/src/org/isf/exa/gui/ExamEdit.java
Exported with compile warnings: AngalTask/src/org/isf/help/gui/AboutWindow.java
Exported with compile warnings: AngalTask/src/org/isf/lab/gui/LabNew.java
Exported with compile warnings: AngalTask/src/org/isf/lab/gui/LabBrowser.java
Exported …Run Code Online (Sandbox Code Playgroud) 当我尝试运行在IntelliJ中创建的jar文件时,我遇到了问题.
我按照这里列出的步骤进行操作:如何正确地从IntelliJ构建罐子?并使用IntelliJ搜索相同问题的其他人,并找不到任何解决方案.
在菜单Project Structure> Artifacts部分中,我有包和主类名,我也尝试使用源文件和.class文件的相对和绝对路径指定'类路径'位(它似乎隐藏在IntelliJ项目显示树..),但即使有这一切(我还确保每次更改内容时重建jar)我得到"找不到主类.程序将退出." 我尝试运行jar时的消息.
在主项目文件夹中,有src和out.
out包含包树的'production',class文件
也包含jar文件夹和jar可执行文件的'artifacts'src
包含一个图像文件夹,META-INF和包树.
包中的第一个文件夹包含主类,所以src/ravelDemo/RavelDemoMain.java
在Project Settings> Artifacts中,主类
目前被列为ravelDemo.RavelDemoMain ,类路径是\ production\RavelSequence v1.03\ravelDemo \但是这个以及我指定的每个其他类路径(或留空)都没有似乎指向正确的地方.(RavelSequence v1.03是项目的名称).
我究竟做错了什么?
到目前为止,从Eclipse导出Runnable JAR文件是从另一台计算机上的命令行启动Eclipse项目的最快方法。看到这个答案。
一个问题是,如果要从其运行的计算机上安装的JRE早于Eclipse使用的JDK,则会出现此错误:
java.lang.UnsupportedClassVersionError: test_hello_world : Unsupported major.minor version 51.0
Run Code Online (Sandbox Code Playgroud)
我知道在Eclipse上我可以以较低的遵从性级别(例如1.6而不是1.7)来构建项目,但这似乎并不影响导出的JAR文件。
关于如何导出要在较旧的JRE上执行的Runnable JAR文件的任何想法吗?
我试图从另一个Java程序执行jar文件.我使用以下代码:
try {
Runtime runtime = Runtime.getRuntime();
runtime.exec("path upto jar");
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Exception occured" + ex);
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我试过谷歌,它给了我使用ProcessBuilder的例子,但这也没有用.
我有一个多模块Gradle项目,我试图升级到2.0.0-M3.按照这里的说明,我将其添加到我的构建脚本中:
springBoot {
executable = true
}
Run Code Online (Sandbox Code Playgroud)
但是当我构建时,我收到以下错误:
Could not set unknown property 'executable' for object of type org.springframework.boot.gradle.dsl.SpringBootExtension.
Run Code Online (Sandbox Code Playgroud)
这是里程碑中的某些东西还是我做错了什么?
executable-jar ×10
java ×9
jar ×5
eclipse ×4
classpath ×1
executable ×1
gradle ×1
manifest ×1
maven ×1
pom.xml ×1
runtime ×1
spring-boot ×1