java - 使用 docker 访问 src/main/resources 中的文件
问题描述
我只是在学习如何在 java 中使用 docker,所以我非常愿意接受建议。
我的项目从上到下都没有问题;但是现在我正在尝试进行本地 docker deploy 我在访问文件夹位置时遇到了问题。
我在本地运行一切;桌面是windows。
我要做的是获取 ffmpeg.exe 并在运行时将 exe 文件移到 jar 旁边。
我猜 docker 有不同的方法可以做到这一点;但我不确定如何寻求帮助。
这是整个方法:
static public String ExportResource(String resourceName) throws Exception {
InputStream stream = null;
OutputStream resStreamOut = null;
String jarFolder;
stream = VideoTranscode.class.getResourceAsStream(resourceName);//note that each / is a directory down in the "jar tree" been the jar the root of the tree
if (stream == null) {
throw new Exception("Cannot get resource \"" + resourceName + "\" from Jar file.");
}
int readBytes;
byte[] buffer = new byte[4096];
jarFolder = new File(VideoTranscode.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile().getPath().replace('\\', '/');
if (!resourceFileAlreadyCopied(resourceName)) {
try {
resStreamOut = new FileOutputStream(jarFolder + resourceName);
while ((readBytes = stream.read(buffer)) > 0) {
resStreamOut.write(buffer, 0, readBytes);
}
} catch (Exception ex) {
throw ex;
} finally {
stream.close();
resStreamOut.close();
}
}
return jarFolder + resourceName;
}
我在这里得到 NPE:
jarFolder = new File(VideoTranscode.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile().getPath().replace('\\', '/');
这是我的码头文件
FROM maven:3-openjdk-8
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
解决方案
推荐阅读
- python - 根据每个数据帧中的列组合比较两个数据帧
- android - 将 TextView 中的文本转换为启动活动的链接
- c++ - MQTT ACL 文件使用
- java - HashTable - 在重新散列中间更改数组大小
- package - Unexpected Token - Atom 教程 - WordCount
- angular - 将引导程序 4 降级到 3.3 角度
- java - 在 Android Studio 中使用 JSoup 获取类头下的文本
- c - c中迷宫程序中的分段错误
- c++ - WINAPI C++ GetDlgItem 不返回有效句柄
- php - 我可以从脚本标签调用我的数据库数据吗?