eclipse - Java, create runnable jar file including ONLY used dependencies. -



eclipse - Java, create runnable jar file including ONLY used dependencies. -

this question has been asked before, have no satisfactory reply yet!

i have java main.java class in project total of other unrelated classes. export main.java executable jar file, containing dependencies uses.

is possible, if how?

both eclipse( create runnable jar ) , intellij ( create artifact ) include dependencies defined in module containing main.java class.

you should using dependency management system, instead of ones provided default in eclipse , idea. many java developers (including me) utilize maven. if you're working in eclipse, includes m2eclipse

you don't want have dependencies in 1 project because can bloated. however, if have maven parent pom uses <dependencymanagement> tag, can reference parent pom , create references dependencies need in sub project. keeps separate separate, , provides easy organization mechanism - reason why people utilize maven.

how utilize <dependencymanagement> in maven

maven has plugins manage jar creation you, e.g. maven-assembly-plugin allow build dependencies how want them in jar , forth.

you have somehow. expect ide / dependency management scheme next code:

test.java

public class test { public static void main(string... args) { system.exit(0); new foo(null); } }

foo.java

import com.google.common.base.preconditions; public class foo { public foo(string s) { preconditions.checknotnull(s); } }

the guava dependency not needed here... know in runtime. if include import statements of classes, include dependencies. if don't, need runtime analysis. problem akin turing halting problem.

java eclipse intellij-idea

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -