• Post Reply Bookmark Topic Watch Topic
  • New Topic

Classpath in Java  RSS feed

 
Rahul Pandya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
directory structure

[root]
/src/main/java/org/datanucleus/samples/jdo/tutorial/*.java java files
/target/classes/org/datanucleus/samples/jdo/tutorial/*.class class files
/lib/*.jar jar files
pom.xml

this command from {root} does not work

java -cp lib\jdo-api.jar;lib\datanucleus-core.jar;lib\datanucleus-mongodb.jar;
lib\datanucleus-api-jdo.jar;lib\{mongodb_jars};target\classes\;.
org.datanucleus.samples.jdo.tutorial.Main

 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It "does not work" isn't enough for us to go on. We actually have a FAQ about that: ItDoesntWorkIsUseless (⇐ Click)

Does it fail to find one of the classes? If so, is it one of your compiled classes that can't be found, or one of the library classes?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a Maven project. Maven is a build tool; a tool to manage building more complex projects, and automatically manage dependencies (automatically find and download libraries that the project needs).

When you have Maven installed, it will be very easy to build the project, with the command: mvn clean package

Maybe the pom.xml also includes a Maven plugin to run the application. But we can't tell without seeing the content of pom.xml. If you want to run it manually, then you'll have to include all the jars etc. manually, as you are trying to do.

Rahul Pandya wrote:this command from {root} does not work

What do you mean with "does not work"? Do you get an error message? What is the exact error message? Error messages contain important information to give you a clue about what's wrong - if you don't give us that information you make it much harder to help you find what the problem is.
 
Rahul Pandya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It did not give any error
In fact it showed "java help"

I have solved the issue .. It was a problem of syntax while using classpath in java

For anyone who needs elaboration on classpath:

For using multiple jars while running a java application, you have to add them to the classpath
manually (using command line) you have to use

[assuming you are at root] && [location of main class is {root}\target\classes\org\test\Main.class && package is org.test]
java -cp <path from root for jar 1>;<path from root for jar 2>;-----and so on ----;<path from root for jar n>;target\classes <space> org.test.Main


Pleasure
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just for completeness, what exactly was wrong with your initial command?

From your description it looks like it SHOULD have worked.
Were your relative paths wrong? or something else in the syntax?

 
Rahul Pandya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There should be no " ; " at end of args for '-cp' &
there was a '.' before 'org'
instead there should be a space

Pleasure

PS: whenever you run a java command from terminal and it shows java --help then most probably it is syntax problem !!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!