How to execute jar file with external dependency using command line on Windows?

I have a jar file with a manifest in it

    Manifest-Version: 1.0
    Build-Jdk: 1.7.0_67
    Created-By: Apache Maven 3.2.3
    Main-Class: com.company.main.Main
    Archiver-Version: Plexus Archiver

      

And the jar will compile the external library dependency

compile 'org.apache.commons:commons-lang3:3.3.2'

      

So, I want to execute the command comandLine, I wrote:

java -cp C:\commons-lang3-3.3.2.jar -jar myJar-1.0.0.jar

      

But

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
        at ...

      

How do I add this file to the classpath?

PS. If I use "bad path" and copy-paste commons-lang3-3.3.2.jar into the ... jre7 \ lib \ ext folder . Everything is working.

+3


source to share


2 answers


If you don't use the -jar parameter, you need to specify the main class to run as the manifest will not be queried:

java -cp C:\commons-lang3-3.3.2.jar;.\myJar-1.0.0.jar com.company.main.Main

      



The classpath (-cp) parameter is ignored when using the -jar option (in this case, the manifest must reference any other required jars via its classpath directive).

+7


source


"Bad way" ..? You should never include jar files in java directories. How do you expect users of your application to use your jar when they use the standard java ..?



either you can use the command suggested by @ tombola82 or you can include the commons-lang banner in your project so you can refer it.

+1


source







All Articles