Avatar of Rohit Bajaj
Rohit Bajaj
Flag for India asked on

Difference between specifying classpath with -cp in command line and in Eclipse-> Run Configurations

I ran a program by giving the following command, the program ran successfully :
java -cp "lib/*;classes" com.yatra.scheduler.runner.MOScheduleSuperPnr

I tried running the same thing from Eclipse. By selecting Run Configurations -> Classpath and then adding all the jars inside lib directory under the User Entries Heading and also the classes folder.

But this gives a runtime error Classdefnotfound.

What could be the reason for this ?
Whats the difference between specifying the classpath in command line using the -cp option and specifying classpath in Eclipse -> Run Configurations->Classpath

JavaEditors IDEs

Avatar of undefined
Last Comment

8/22/2022 - Mon

Whats the difference between specifying the classpath in command line using the -cp option and specifying classpath in Eclipse -> Run Configurations->Classpath
There should be no difference. Can you post a screenshot of the "Classpath" page from the Run Configurations dialog?

What could be the reason for this ?


a. you missed at least one jar
b. the lib folder also includes classes NOT in jars
Rohit Bajaj

I think i spotted the problem. Any comments on improving will be helpful.

For the normal run of the code i am running the following command :

java -cp "lib/*;classes" com.yatra.scheduler.runner.MOScheduleSuperPnr

under the directory E:\SvnCheckOut\trunk\MOScheduler\target\MOScheduler

But in eclipse i directly click on run under the file


And so it gives the following error :
org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'classes/velocity/flight_booking.vm'

Now during command prompt running this error was not coming.
Due to the fact that classes folder was present under E:\SvnCheckOut\trunk\MOScheduler\target\MOScheduler

How do i correct this or whats the proper way to run it in eclipse. I need to debug it in eclipse.

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

Sounds like you have not set the Eclipse project up properly. You'd probably be better off creating a new project and making sure you have got the build path and packaging correct.

That is, of course if it's not already an Eclipse project. If it is, it should contain a .project file

Ok, so the problem is that you are trying to load your velocity resource as a file via a relative path. So the working directory that current when you first launch the app is critical to it working.

Quick and dirty solution... Go into your Run Configuration in Eclipse and then on either the Arguments tab or Environment tab (I forget exactly which one), there is a field to be able to set the working directory. Set this to the same directory that you are in on the command line and then it should work from eclipse too.

However what you should do is have Velocity load the .vm file via the classpath rather than as a file. First check out Velocity's ClasspathResouceLoader, but for exactly how to enable this, you would have to tell us exactly how you are using Velocity, ie. do you manually instantiate a VelocityEngine from code, or do you use some integration with another technology such as Spring, etc?

Yes, certainly it's better to load your templates as resources:


A natural way (close to the Java standard one is)

Resource r = org.apache.velocity.util.ClassUtils.getResourceAsStream(getClass(), "/resources/flight_booking.vm");

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Rohit Bajaj

I am calling velocity at the line :
Template velocityTemplate = velocityEngine.getTemplate(vmFilePath);
Here vmFilePath = classes/velocity/flight_booking.vm

Its failing at this point.

I tried changing the working directory in Eclipse argument tab. It worked perfectly.
Please also let me know the other approach.
Which is the better one to use ?


Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question