Building jar the simple way?
Hi, i'd like to build a java jar, it is dealing with processing csv files into database. I am using several libraries and i have some configuration files outside src folder.
How can I actually create the jar with the configuration files included, and all the classpath has been defined.
I'm trying the build jar.. that IDEA 9M1 has, and found that the config files cannot be included and the jar is all put inside the jar file, but somehow the classpath is not set.
Am I building the jar correctly?
Any hint?
Thank you for the help!
Robert
请先登录再写评论。
jar in jar is never going to work.
Instead you have to set a dependency on the other jars in the manifest file.
The jar builder in IntelliJ sadly isn't intelligent enough to do that for you.
Apart from that you will have to set the directory containing your other files as a project directory, and include it in the build so the files get pulled into the compiled target.
Best thing to do would be to create a small batch script that creates the jar file for you, and feed that with the directories to be included and a custom created manifest file.
Exclude the lib directory (or whereever your external jars are located) from the jar command, and instead copy the content of that to the directory where you place the jar.
For my SCJD submission I created the following batch script to generate the submission jar (that's just a distribution file so does contain other jars, not being meant to be executed, but the principle is the same:
@echo off
echo preparing submission
echo copying files
copy SCJD\runme.jar .
copy docs\db-2x2.db .
attrib -r db-2x2.db
copy docs\version.txt .
echo creating submission source folder
xcopy code\* src\code /I /S /Q /EXCLUDE:exclude.txt
echo building submission jar
jar -cf scjda-SR1899379.jar runme.jar docs\javadoc\* version.txt docs\choices.txt docs\instructions.html db-2x2.db docs\userguide.txt
rmdir /S /Q src\CVS
jar -uf scjda-SR1899379.jar -C src .
echo cleaning up
del runme.jar
del version.txt
rmdir /S /Q src
exclude.txt is a text file containing file patterns xcopy is to ignore. You can use that to avoid packing your external jars.
Are you sure about that? Last time I tried this worked fine. In the "Build
Jars" dialog just select the jar you want to link to, click "Edit" and choose
"Link via manifest and copy files to".
Thanks, you got it right, idea supports the manifest linking via Edit....
Thanks a lot!
Robert
hadn't noticed that option. Was wondering why it was missing in fact.
Hi,
I was also using this option in Intellij 8.x but I cannot find this in intellij 9.
Is this reallt available in Intellij 9, I looked everywhere I think
Hi.
In IDEA 9 Build jars dialog is replaced with artifacts feature. Application help contains some topics on it.
Alexander.
Hi,
I've tried to build jar using artifacts but I couldn't find the equivalent of "Packaging method" in Idea 9.
I looked the help topics and still no progress.
Thanks,
Engin