• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Explanation of java -cp command

 
Suril J Sarvaiya
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to do a deployement on a server and have a java command which goes like this :

java -cp $JBOSS_HOME/bin/client/jboss-client.jar:. test.Client ejb:/client-ejb//ClientBean\!test.ClientIF

I will divide it into few parts :

1) java -cp (what does this do on the whole command, i dont know which part does it copy where?)
2) $JBOSS_HOME/bin/client/jboss-client.jar:. (the path till client.jar is fine, but what does :. indicate)
3) test.Client (its my ejb client, no issues here)
4) ejb:/client-ejb//ClientBean\!test.ClientIF (jndi lookup name, no issues here also)

I want to know what will this whole command do when executed?
It gives me a noclassdeffound error but i cant understand what is its aim? what does it tell the jvm to do?

all help wud be hugely appreciated.
thanks
regards,

Suril
 
Stephan van Hulst
Saloon Keeper
Posts: 10522
224
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java tells the command line to execute java.exe, of course.

-cp is an option that you feed to java.exe. It tells the JVM that you want to use a custom classpath, specified by the next command line argument.

$JBOSS_HOME/bin/client/jboss-client.jar:. is the argument that goes with the -cp option. It should consist of a series of file paths, separated by colons. So you're telling the JVM that you want
$JBOSS_HOME/bin/client/jboss-client.jar to be on the classpath, and that you want . (the current working directory) to be on the classpath.

test.Client is the name of the class the JVM should execute.

Everything after that will be command line arguments that are fed to test.Client's main method.
 
Campbell Ritchie
Marshal
Posts: 65423
248
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should find the -cp tag here. The . adds the current directory to the classpath. The rest is as Stephan has already told you.
 
Suril J Sarvaiya
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Stephan and Campbell................
hugely relieved..........!!!

now to take it forward ... why am I getting noclassdeffound error....??
everything is in place as far as classpath is concerned.......

also my ejb jar has been compiled successfully.............

any idea guys?
 
Ivan Jozsef Balazs
Rancher
Posts: 1039
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> test.Client

Is there a Client.class located somewhere? Exactly where? Is this available?

test/Client.class
 
Suril J Sarvaiya
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah....
my directory structure is :
Parent Directory : jboss-ejb which has :

test > Client.java, ClientIF.java, ClientBean.java
client-ejb.jar
jndi-property file
jboss-ejb-client property file
 
Ivan Jozsef Balazs
Rancher
Posts: 1039
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Suril J Sarvaiya wrote:yeah....
Parent Directory : jboss-ejb which has :

test > Client.java, ClientIF.java, ClientBean.java
client-ejb.jar
jndi-property file
jboss-ejb-client property file



There seem to be no classes there.

In order for this
-cp $JBOSS_HOME/bin/client/jboss-client.jar:. test.Client
to work the class Client of the package test should either be located as ./test/Client.class or as test/Client.class inside the cited jboss-client.jar.
It is pretty much elementary Java classpath stuff.

Maybe you have only the sources in the above directory without having translated them.

 
Suril J Sarvaiya
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ivan,

I just mistyped it.
.class files are present in the test folder as well in the ejb-client.jar

Suril
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the current directory when you execute the command? Is it the directory that contains the "test" directory? Because that's where you should be.

Otherwise, you could specify the directory that contains the "test" directory explicitly in the classpath, instead of "." (the current directory).
 
Suril J Sarvaiya
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jesper.....
Yes 'test' folder is in jboss-ejb folder which is the current directory.
Nevertheless, I tried by passing the whole path instead of the .
still the same problem exists.
 
Suril J Sarvaiya
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will describe exactly what I have done :

---->>
This is my folder structure :

jboss-ejb/
.........jndi.properties
.........jboss-ejb-client.properties
.........test/
.............ClientIF.java
.............ClientBean.java
.............Client.java

---->>
javac -cp $JBOSS_HOME/bin/client/jboss-client.jar test/*java
jar cvf client-ejb.jar test/ClientIF.class test/ClientBean.class
cp client-ejb.jar $JBOSS_HOME/standalone/deployments/

---->>
java -cp $JBOSS_HOME/bin/client/jboss-client.jar:. test.Client ejb:/client-ejb//ClientBean\!test.ClientIF ------- The problem creator line...!!

Hope this helps you all to identify the issue...!!
Thanks again..


 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, what is the exact error message that you get (copy and paste it here)? It tells you exactly which class it cannot find.
 
Suril J Sarvaiya
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the exact error message is :

Exception in thread "main" java.lang.NoClassDefFoundError: C:/Users/surils/Desktop/jboss-ejb/test/Client/class
Caused by: java.lang.ClassNotFoundException: C:.Users.surils.Desktop.jboss-ejb.test.Client.class
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha! Are you typing ".class" after the class name somewhere? For example, are you really typing:

java -cp $JBOSS_HOME/bin/client/jboss-client.jar:. test.Client.class ...

instead of:

java -cp $JBOSS_HOME/bin/client/jboss-client.jar:. test.Client

Note that the java command takes a class name, not the filename of a class file. So you must not add the ".class" extension.
 
Suril J Sarvaiya
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heyy...I tried doing it both the ways...
Initially I just wrote the class name, it did not work then I just tried with .class extension..but the same problem on both the occassions..
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!