Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Classpath in Java

 
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

 
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • 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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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
 
Bartender
Posts: 1845
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 !!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic