java - How to create a single jar from multiple packages?
问题描述
I want to create a single jar file from multiple packages. I have created the jar using below command but when I'm importing it to a project as a dependency it is not working.
jar cfe output/jar/my-java.jar Main src/pkg1/pkg0/*.class src/pkg1/*.class src/pkg2/*.class
My project structure is something like below structure
src
pkg1
A.java
B.JAVA
pkg0
E.java
pkg2
C.java
D.java
My Example code is something like
import pkg1.A;
public class Main {
public static void main(String[] args) {
A.printMe("Hello World");
}
}
error that I'm getting is:
java pkg1 not exist But in the editor(IntelliJ), it is not showing errors and also i'm able to import class but not package.
- import pkg1: showing red means error in the editor
- import pkg1.A: not showing red means no error in the editor
Note: I don't want to use maven.
解决方案
An unzip -t something.jar
shows the actual file structure of the jar file (zip). It is the same as the class structure of it (except that instead "/
", a ".
" is the separator).
In your case, the problem will be that src
will be on the top level, and not pkg1
. Either import src.pkg1
(very dirty), or play a little bit more with the directories / jar flags.
推荐阅读
- azure-application-insights - ApplicationInsights.config 是否需要位于输出目录的根目录中
- node.js - 等待 node.js/express 中的 Google Vision OCR 承诺并返回
- sas - 获取两个特定字符位置之间的字符串
- python - 如何使用 python 格式化我的 json
- android - 在Android中对齐两个视图的垂直中心
- localization - 通过 Typoscript 将翻译添加到 TYPO3 扩展
- asp.net - 使用 ng-include 时 MVC 路由不起作用
- python - Keras 的回调 evaluate_generator
- c++ - 没有堆的两种方式构造对象
- php - 与服务相关的活动正确显示