我有一个程序,它使用名为 list.txt 的文件用其内容填充 ArrayList,然后获取随机行。
这是加载文件的部分:
public class ReadList {
private Scanner f;
public void openFile(){
try{
f = new Scanner(new File("list.txt"));
}catch(Exception e){
System.out.println("File not found!");
}
}
Run Code Online (Sandbox Code Playgroud)
但是,从 .jar 文件运行它时它不起作用。我把txt放在同一个目录下并使用,f = new Scanner(new File("./list.txt"));但它不起作用。我还尝试了一些我在网上找到的东西,但我所能做的就是a)获取包含.jar的.jar的完整路径(/home/user/java/program.jar),以及b)获取完整的路径目录的路径,但末尾没有 / (/home/user/java),这是一个问题,因为我希望这个程序在 Windows 和 Linux 上都能工作,因此我不能简单地执行 ("/home/user /java" + "/list.txt"),因为 Windows 在路径中使用反斜杠。
那么,无论文件位于哪个目录,只要它与 .jar 位于同一位置,只定位特定文件(始终称为 list.txt)的简单方法是什么?
我正在运行具有 Debian 8.0 64 位、512 MB RAM 和 150GB 空间的 Linux vServer。
计划将其用于游戏并让 Server.jar 不间断运行。服务器与 Kryonet 一起工作,Kryonet 是一个用于简单客户端/服务器通信的库。在我的服务器上,我安装了 Java 1.8,它工作正常,为了测试,我下载了 Minecraft 服务器 jar,它工作得很好。所以我用 eclipse 将我的服务器打包到可执行 jar 中(编译版本 1.8),在我的计算机(安装了 Java 8)上使用 cmd 启动它时工作正常,但是当尝试在服务器上启动它时:错误:无效或损坏的 jarfile 服务器。罐
我认为这可能是我使用的库的问题,所以我尝试了一个干净的 HelloWorld jar,也不起作用。
我目前正在从事一个Java项目,我们使用maven来构建最终的jar。众所周知,有两种构建 jar 的方法,即一种带有依赖项的单个 jar 和一种不带依赖项的 jar。在后一种情况下,我们还需要将依赖 jar 添加到类路径中。
原则上两者都可以工作,我个人更喜欢一个带有依赖项的 jar,但在项目团队成员中决定使用单独的没有依赖项的 jar。所以我想知道哪种选择更好?
从哪里以及如何下载以前版本的 selenium jar?目前我只能从 seleniumHQ 下载 selenium 3.0。我需要下载 2.53 版本的 selenium。
我成功地将 OSGi 特定元数据添加到 Flying-saucer-pdf Maven 工件的 MANIFEST 中。但是,我没有成功将该工件的依赖项和传递依赖项嵌入到创建的 JAR 文件中。
我使用来自 GitHub [1] 的 Flying-saucer-pdf 的原始来源,并将以下语句添加到 pom.xml 文件中:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<instructions>
<Embed-Dependency>itext</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
该工件在其原始 pom.xml 中声明了对 itext 版本 2.1.7 的依赖项,我没有触及该依赖项。我也没有弄乱工件的原始包装类型,即 jar。
不幸的是,这仅完成了部分工作。MANIFEST.MF 似乎正确并且包含预期的 OSGi 标签:
Manifest-Version: 1.0
Bundle-Description: Flying Saucer is a CSS 2.1 renderer written in Jav
a. This artifact supports PDF output.
Bundle-License: http://www.gnu.org/licenses/lgpl.html
Bundle-SymbolicName: org.xhtmlrenderer.flying-saucer-pdf …Run Code Online (Sandbox Code Playgroud) 我需要创建一个包含模块内部包中已编译类的 jar。我有一个 jar 文件,它实际上是模块内部的一个包,我需要重新创建它。
我可以创建整个模块的 jar,但无法创建包的 jar 文件。我怎样才能按照想法做到这一点?
这些有什么区别呢Spring Boot jars。
spring-boot-starter-data-mongodb jar
spring-data-mongodb jar
mongodb 驱动程序 jar
mongodb-驱动程序核心 jar
我对这些的理解是mongodb-drivermongoDB 的 java 驱动程序。对于许多人来说,它spring-boot-starter-data-mongodb就像 Spring Boot 一样入门(spring-boot-starter-web,spring-boot-starter-test)。
有人可以解释一下他们在 中的角色吗Spring boot?
关于 SO 的许多问题都涉及 Spring-Boot webjar 中各种资源的无效路径。目前我遇到了 tether 的问题,但我不想再专门写一个关于 tether 的 webjar 文件/路径的问题,所以想问一下:
干杯
PS:jquery、bootstrap 对我来说工作得很好。我的系绳 webjar 没有。
<script th:src="@{/webjars/tether/1.4.3/js/tether.min.js}" crossorigin="anonymous"></script>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Kotlin 创建一个可运行的 jar。
我的 gradle.build 是这样的:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.11'
}
group 'com.github.dynamik'
version '1.0-SNAPSHOT'
apply plugin: 'application'
apply plugin: 'kotlin'
mainClassName = "interpreter.Repl"
repositories {
mavenCentral()
maven { setUrl("https://dl.bintray.com/hotkeytlt/maven") }
}
configurations {
ktlint
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile 'com.github.h0tk3y.betterParse:better-parse-jvm:0.4.0-alpha-3'
// https://mvnrepository.com/artifact/junit/junit
testCompile group: 'junit', name: 'junit', version: '4.4'
ktlint "com.github.shyiko:ktlint:0.31.0"
implementation 'com.github.ajalt:clikt:1.7.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.0'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
run {
standardInput = System.in
}
jar …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置一个模拟服务器wireMock作为独立进程。我下载了 jar 文件并执行了以下命令:
java -jar wiremock-standalone-2.23.2.jar --port 0
Run Code Online (Sandbox Code Playgroud)
我必须动态确定端口,因为我已经在我的计算机上运行的另一个程序使用默认的 8080 端口。它给了我端口号 55142,但是当我尝试在网络上访问该端口时,它给了我以下错误:
HTTP ERROR 403
Problem accessing /__files/. Reason:
Forbidden
Powered by Jetty://
Run Code Online (Sandbox Code Playgroud)