Netbeans Export to Jar, include all library files

China☆狼群 提交于 2019-11-30 12:35:07
user845279

I prefer this solution since there is nothing to download, all based on Ant build (~20 lines). That way there is no additional dependency to bother with. If you have a couple of minutes, you can learn about Ant too.

It seems like the link to the original Article is broken (thanks Oracle). Here is another link.

The original article is also available from Oracle link.

  1. Open the generated jar with 7zip (or others tools)
  2. Add the jar library into the folder
  3. Edit the manifest to set the class path

Okay, so this is my solution. I too had the problem my programmme compiling and running on Netbeans but it failing when I tried Java -jar MyJarFile.jar Now, I don't fully understand Maven and I think this why was having trouble getting Netbeans 8.0.2 to include my jar file in a library to put them into a jar file. I was thinking about how I used to use jar files with no Maven in Eclipse.

It's Maven that compiles all the dependanices and plugins. Not Netbeans. (If you can get Netbeans to do this please tell us how (^.^)v )

[Solved - for Linux] by opening a terminal.

Then

cd /MyRootDirectoryForMyProject

Next

mvn org.apache.maven.plugins:maven-compiler-plugin:compile

Next

mvn install

This will create jar file in the target directory.

MyJarFile-1.0-jar-with-dependencies.jar

Now

cd target

(You may need to run: chmod +x MyJarFile-1.0-jar-with-dependencies.jar) And finally

java -jar MyJarFile-1.0-jar-with-dependencies.jar

Please see

https://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException

I'll post this solution in on a couple of other pages with a similar problem. Hopefully I can save somebody from a week of frustration.

There's no built in way to do this. You can, however, use external tools to archive this like OneJar:

http://one-jar.sourceforge.net/

Edit: Apparently this is even the way the Netbeans team expects you to do it: http://wiki.netbeans.org/PackagingADistributableJavaApp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!