我正在尝试构建一个可执行的jar程序,它取决于下载的外部jar.在我的项目中,我将它们包含在构建路径中,并且可以在eclipse中运行和调试.
当我尝试将它导出到jar时,我可以运行该程序,但是当我尝试按下包含来自外部jar的函数调用和类的按钮时,我无法运行.我编辑了环境变量(Windows XP)CLASSPATH以包含所有外部jar的路径,但它不起作用.
需要注意的一点是,我在导出可执行jar时遇到了编译警告,但它没有显示有关警告的任何描述.
有人会提供一个关于如何使用eclipse包含外部jar程序的详尽指南吗?
我使用Eclipse(3.4)并且我的类编译时没有警告或错误.我的项目使用外部jar文件.
我需要在哪里放置这个外部jar文件,以便java.lang.NoClassDefFoundError在从另一个项目(而不是在Eclipse)中使用这个类时不会得到它?
我可以将jar解压缩到项目文件夹中,但这感觉不对.
编辑:这个问题不是关于在Eclipse中导入jar,而是在Eclipse之外使用它们.
我有一个包含清单文件的webapp,我在其中编写了一个ant构建任务期间我的应用程序的当前版本.清单文件是正确创建的,但是当我尝试在运行时读取它时,我会得到一些奇怪的副作用.我在清单中阅读的代码是这样的:
InputStream manifestStream = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream("META-INFFFF/MANIFEST.MF");
try {
Manifest manifest = new Manifest(manifestStream);
Attributes attributes = manifest.getMainAttributes();
String impVersion = attributes.getValue("Implementation-Version");
mVersionString = impVersion;
}
catch(IOException ex) {
logger.warn("Error while reading version: " + ex.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
当我将eclipse附加到tomcat时,我看到上面的代码有效,但它似乎得到了一个不同于我预期的清单文件,我可以告诉它,因为ant版本和构建时间戳都是不同的.然后,我在那里放了"META-INFFFF",上面的代码仍然有效!这意味着我正在阅读其他一些清单,而不是我的清单.我也试过了
this.getClass().getClassLoader().getResourceAsStream(...)
Run Code Online (Sandbox Code Playgroud)
但结果是一样的.从tomcat中运行的webapp内部读取清单文件的正确方法是什么?
编辑:感谢您的建议到目前为止.另外,我应该注意到我正在运行tomcat独立; 我从命令行启动它,然后附加到Eclipse调试器中正在运行的实例.这不应该有所作为,不是吗?
我在java文件(MyRtmpClient.java)中有以下内容:
import org.apache.mina.common.ByteBuffer;
Run Code Online (Sandbox Code Playgroud)
并且ByteBuffer位于JAR文件中(当然具有正确的目录结构).我需要的jar文件和其他文件与.java文件位于同一目录中.
然后我用这行编译:
javac -cp ".;*.jar" MyRtmpClient.java
Run Code Online (Sandbox Code Playgroud)
但我得到错误:
MyRtmpClient.java:3: package org.apache.mina.common does not exist
import org.apache.mina.common.ByteBuffer;
如何在项目中包含jar文件?
我正在创建一个Python脚本,我在其中执行UNIX系统命令.我有一个名为Binaries.war的war存档,它位于名为Portal.ear的ear存档中
Portal耳朵文件位于/ home/foo/bar /
jar xf /home/foo/bar/Portal.ear Binaries.war
Run Code Online (Sandbox Code Playgroud)
将/home/foo/bar/Portal.ear存档中的Binaries.war文件解压缩到我运行脚本的当前目录中.
如何使用一个命令指定要提取的目标目录?我想做这样的事情来将Binaries.war提取到目录/ home/foo/bar/baz中
jar xf /home/foo/bar/Portal.ear Binaries.war [into target directory /home/foo/bar/baz]
Run Code Online (Sandbox Code Playgroud)
我搜索了JAR手册页中的选项,似乎无法找到一种简单的方法来执行此操作.当然,我可以将存档提取到我当前的目录中,然后使用mv移动它,但我想一次性完成此操作,而不是随机播放目录和文件.
我想我的输出罐子,罐子,有依赖性的地方到另一个文件夹(不在target/,但在../libs/).
我怎样才能做到这一点?
我有一个Spring Boot应用程序,我已经创建了一个Jar.以下是我的pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- WebJars -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
我想在我的其他应用程序中使用此Jar,因此将此jar添加到我的应用程序中.但是,当我在那个Jar中调用一个方法时,它正在抛出一个ClassNotFoundException.
我该如何解决这个问题?如何向Spring Boot JAR添加依赖项?
我有一个Eclipse Java项目.它包含一个名为"dist"的文件夹.在该文件夹中是.jar文件.
如何在此项目中进行设置以确保在重新编译项目中的一个.java文件时更新此.jar文件?
谢谢.
我有一个项目,我想加载一个速度模板来完成它与参数.整个应用程序打包为jar文件.我最初想到的是这样的:
VelocityEngine ve = new VelocityEngine();
URL url = this.getClass().getResource("/templates/");
File file = new File(url.getFile());
ve = new VelocityEngine();
ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, file.getAbsolutePath());
ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, "true");
ve.init();
VelocityContext context = new VelocityContext();
if (properties != null) {
stringfyNulls(properties);
for (Map.Entry<String, Object> property : properties.entrySet()) {
context.put(property.getKey(), property.getValue());
}
}
final String templatePath = templateName + ".vm";
Template template = ve.getTemplate(templatePath, "UTF-8");
String outFileName = File.createTempFile("report", ".html").getAbsolutePath();
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(outFileName)));
template.merge(context, writer);
writer.flush();
writer.close();
Run Code Online (Sandbox Code Playgroud)
当我在eclipse中运行时,这很好用.但是,一旦我打包程序并尝试使用命令行运行它,我得到一个错误,因为找不到该文件.
我想问题就在这一行:
ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, file.getAbsolutePath()); …Run Code Online (Sandbox Code Playgroud)