Code Comments
Programming Forum and web based access to our favorite programming groups.I would like to compile and execute (run) without changing directories. Currently, however, I get the following error: thufir@arrakis:~/java$ thufir@arrakis:~/java$ javac -cp src -d /home/thufir/java/build/ src/com/ web_tomorrow/CPTest2.java thufir@arrakis:~/java$ thufir@arrakis:~/java$ java build.com.web_tomorrow.CPTest Exception in thread "main" java.lang.NoClassDefFoundError: build/com/ web_tomorrow/CPTest thufir@arrakis:~/java$ thufir@arrakis:~/java$ To get good output, only this seems to work: thufir@arrakis:~/java/src$ thufir@arrakis:~/java/src$ javac -cp . -d /home/thufir/java/build/ com/ web_tomorrow/CPTest2.java thufir@arrakis:~/java/src$ thufir@arrakis:~/java/src$ cd .. thufir@arrakis:~/java$ thufir@arrakis:~/java$ cd build/ thufir@arrakis:~/java/build$ thufir@arrakis:~/java/build$ java com.web_tomorrow.CPTest2 Run CPTest2.main() thufir@arrakis:~/java/build$ thufir@arrakis:~/java/build$ how can I do this without changing directories? thanks, Thufir
Post Follow-up to this message>how can I do this without changing directories? nowadays people do this with ant, not bat files. See http://mindprod.com/jgloss/ant.html If you want to do it the hard way, see http://mindprod.com/jgloss/classpath.html http://mindprod.com/jgloss/javacexe.html -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Post Follow-up to this messageThufir wrote: > thufir@arrakis:~/java$ java build.com.web_tomorrow.CPTest I think this is the problem here. The package name for your class is not build.com.web_tomorrow . It's just com.web_tomorrow. Try setting the class path to build and executing the class. Maybe: java -cp ./build com.web_tomorrow.CPTest You may have other errors if you are relying on the classpath from the environment. You'll have to add those paths to the command line too if you are using the CLASSPATH variable.
Post Follow-up to this messageOn Thu, 20 Mar 2008 09:46:40 -0700, Mark Space wrote: > I think this is the problem here. The package name for your class is > not build.com.web_tomorrow . It's just com.web_tomorrow. Try setting > the class path to build and executing the class. Exactly, the package is com.web_tomorrow as per: http://www.kevinboone.com/classpath.html It wouldn't make sense to have a package of build.com.web_tomorrow, or would it? Sounds odd to me, I thought the convention was for packages to begin with com,net,org, etc (where possible). -Thufir
Post Follow-up to this messageOn Thu, 20 Mar 2008 12:50:34 +0000, Roedy Green wrote: > nowadays people do this with ant, not bat files. See > http://mindprod.com/jgloss/ant.html What about ruby? or raven? -Thufir
Post Follow-up to this messageThufir wrote: > It wouldn't make sense to have a package of build.com.web_tomorrow, or > would it? Sounds odd to me, I thought the convention was for packages to > begin with com,net,org, etc (where possible). Or they begin with java. Or javax. Or anything that doesn't collide with some other package name. ;-) Btw, did you get your java runtime issue working?
Post Follow-up to this messageOn Thu, 20 Mar 2008 19:50:43 GMT, Thufir <hawat.thufir@gmail.com> wrote, quoted or indirectly quoted someone who said : >What about ruby? or raven? ant is a specialised tool for doing builds. Ruby is a general purpose language. -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
Post Follow-up to this messageThufir wrote: > I would like to compile and execute (run) without changing directories. > Currently, however, I get the following error: > > thufir@arrakis:~/java$ > thufir@arrakis:~/java$ javac -cp src -d /home/thufir/java/build/ src/com/ > web_tomorrow/CPTest2.java > thufir@arrakis:~/java$ > thufir@arrakis:~/java$ java build.com.web_tomorrow.CPTest > Exception in thread "main" java.lang.NoClassDefFoundError: build/com/ > web_tomorrow/CPTest > thufir@arrakis:~/java$ > thufir@arrakis:~/java$ > > > > To get good output, only this seems to work: > > > thufir@arrakis:~/java/src$ > thufir@arrakis:~/java/src$ javac -cp . -d /home/thufir/java/build/ com/ > web_tomorrow/CPTest2.java > thufir@arrakis:~/java/src$ > thufir@arrakis:~/java/src$ cd .. > thufir@arrakis:~/java$ > thufir@arrakis:~/java$ cd build/ > thufir@arrakis:~/java/build$ > thufir@arrakis:~/java/build$ java com.web_tomorrow.CPTest2 > Run CPTest2.main() > thufir@arrakis:~/java/build$ > thufir@arrakis:~/java/build$ > > > > how can I do this without changing directories? > > > thanks, > > Thufir > You can't classpath your way out of this problem. You must be in a directory that is above the packages you wish to access. You can't point your classpath at source files only .class files and .jars. I've never used ant (I'll have to look into that) but making a simple batch file is very easy. For development I make a compile batch file and a run batch file so I just have to type a couple of keystrokes after I edit my program. -- Knute Johnson email s/nospam/linux/ -- Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ------->>>>>>http://www.NewsDem
Post Follow-up to this messageOn Thu, 20 Mar 2008 23:36:59 +0000, Mark Space wrote: > Or they begin with java. Or javax. Or anything that doesn't collide > with some other package name. ;-) > > Btw, did you get your java runtime issue working? Yes; it was just a variation of this problem. -Thufir
Post Follow-up to this messageOn Thu, 20 Mar 2008 19:10:08 -0700, Knute Johnson wrote: > You can't classpath your way out of this problem. You must be in a > directory that is above the packages you wish to access. Thanks, Thufir
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.