我有一个项目,包含一个单独的模块,和一些依赖。 我想在一个单独的目录中创建一个JAR,其中包含编译后的模块。此外,我希望在我的模块旁边有依赖项。
无论我如何扭曲IntelliJ的“构建JAR”过程,我的模块的输出都是空的(除了一个META-INF文件)。
我有一个项目,包含一个单独的模块,和一些依赖。 我想在一个单独的目录中创建一个JAR,其中包含编译后的模块。此外,我希望在我的模块旁边有依赖项。
无论我如何扭曲IntelliJ的“构建JAR”过程,我的模块的输出都是空的(除了一个META-INF文件)。
当前回答
8.1.3想法
Jar是可以的,因为在'output'目录(project/out/production//)中有编译输出
我猜,你必须在构建jar之前运行'make'
对于依赖项,只需检查“show library”并选择您想要的。
其他回答
如果您在项目中使用第三方库,或者在创建MANIFEST时遇到问题。MF文件,在运行使用
File > Project Structure > Artifacts > '+' > JAR > From modules with dependencies > .....
上述方法。
相反,我建议您创建一个空JAR,并手动将所有其他元素添加到输出根中。关于这种方法的一篇精彩的博客文章可以在这里找到:http://karthicraghupathi.com/2016/07/10/creating-an-executable-jar-in-intellij-idea/我尝试了上面提到的步骤,一切都很顺利!
当我使用这些解决方案这个错误来:
java -jar xxxxx.jar
在xxx.jar中没有主清单属性
解决方案是:
您必须更改清单目录:
<project folder>\src\main\java
将Java更改为资源
<project folder>\src\main\resources
使用
mvn clean package spring-boot:repackage
在IntelliJ终端中输入以上命令。它生成一个带有Executable Jar的目标文件。
这可能有点晚,但我设法解决它的方式-> 用winrar打开并删除ECLIPSEF。RSA和ECLIPSEF。SF在META-INF文件夹中,并且在MANIFEST.MF中放置“Main-class: main_class_name”(没有“.class”)。确保你在最后一行之后按了两次“Enter”,否则它将不起作用。
如果您正在阅读这个答案,因为您面临“资源文件未找到”错误,请尝试以下方法:
File -> Project Structure -> Artiface -> New, type is Other. Give it a nice name, and in the Output Layout, press Create Archive to create a new jar, and again, give it a nice name ;) Click on the jar you just added, add your compiled module output in the jar. Click on the jar again, in the lower pane, select your project path and add Manifest File then set correct Main Class and Class Path. Click Add Library Files, and select libraries you need (you can use Ctrl+A to select all). Build -> Build Artifact -> Clean & Build and see if the error is gone.