Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

javac classpath; where to compile from?
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


Report this thread to moderator Post Follow-up to this message
Old Post
Thufir
03-20-08 01:19 PM


Re: javac classpath; where to compile from?
>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

Report this thread to moderator Post Follow-up to this message
Old Post
Roedy Green
03-20-08 01:19 PM


Re: javac classpath; where to compile from?
Thufir 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.



Report this thread to moderator Post Follow-up to this message
Old Post
Mark Space
03-21-08 12:23 AM


Re: javac classpath; where to compile from?
On 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


Report this thread to moderator Post Follow-up to this message
Old Post
Thufir
03-21-08 12:23 AM


Re: javac classpath; where to compile from?
On 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


Report this thread to moderator Post Follow-up to this message
Old Post
Thufir
03-21-08 12:23 AM


Re: javac classpath; where to compile from?
Thufir 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?

Report this thread to moderator Post Follow-up to this message
Old Post
Mark Space
03-21-08 12:23 AM


Re: javac classpath; where to compile from?
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Roedy Green
03-21-08 03:18 AM


Re: javac classpath; where to compile from?
Thufir 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

Report this thread to moderator Post Follow-up to this message
Old Post
Knute Johnson
03-21-08 03:18 AM


Re: javac classpath; where to compile from?
On 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


Report this thread to moderator Post Follow-up to this message
Old Post
Thufir
03-21-08 09:43 AM


Re: javac classpath; where to compile from?
On 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


Report this thread to moderator Post Follow-up to this message
Old Post
thufir
03-29-08 12:31 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:32 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.