944,184 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 7345
  • Java RSS
Mar 25th, 2006
0

compiling from command line

Expand Post »
Hello everyone.

At the moment I'm compiling all my .java files in the same directory where the javac program is. I know this is a bad idea.

How do I link it from the command line and let's say export the .class files to another directory of my choice.

ThanQ
Similar Threads
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Mar 25th, 2006
0

Re: compiling from command line

I would recommend looking into Ant. It has a task called javac that should do what you're looking to do.
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Mar 25th, 2006
0

Re: compiling from command line

Yeah I'll probably use that later, especially if it supports easy to make jar executables however, in the mean time do you know how to do it from the command line.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Mar 25th, 2006
0

Re: compiling from command line

http://java.sun.com/j2se/1.5.0/docs/...ris/javac.html

it looks like the -d option is what you want.
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Mar 31st, 2006
0

Re: compiling from command line

Ok I still can't do this?

Let's say this is where my javac program is:

Java Syntax (Toggle Plain Text)
  1. c:\j2sdk1.4.2_04\bin


And this is where I have written my program

Java Syntax (Toggle Plain Text)
  1. c:\java files\hello.java

How do I compile hello.java so that the class files appear in the same directory?


I assume these commands have something to do with it. Please help me
:cry:


Java Syntax (Toggle Plain Text)
  1. Usage: java [-options] class [args...]
  2. (to execute a class)
  3. or java [-options] -jar jarfile [args...]
  4. (to execute a jar file)
  5.  
  6. where options include:
  7. -client to select the "client" VM
  8. -server to select the "server" VM
  9. -hotspot is a synonym for the "client" VM [deprecated]
  10. The default VM is client.
  11.  
  12. -cp <class search path of directories and zip/jar files>
  13. -classpath <class search path of directories and zip/jar files>
  14. A ; separated list of directories, JAR archives,
  15. and ZIP archives to search for class files.
  16. -D<name>=<value>
  17. set a system property
  18. -verbose[:class|gc|jni]
  19. enable verbose output
  20. -version print product version and exit
  21. -version:<value>
  22. require the specified version to run
  23. -showversion print product version and continue
  24. -jre-restrict-search | -jre-no-restrict-search
  25. include/exclude user private JREs in the version search
  26. -? -help print this help message
  27. -X print help on non-standard options
  28. -ea[:<packagename>...|:<classname>]
  29. -enableassertions[:<packagename>...|:<classname>]
  30. enable assertions
  31. -da[:<packagename>...|:<classname>]
  32. -disableassertions[:<packagename>...|:<classname>]
  33. disable assertions
  34. -esa | -enablesystemassertions
  35. enable system assertions
  36. -dsa | -disablesystemassertions
  37. disable system assertions
  38. -agentlib:<libname>[=<options>]
  39. load native agent library <libname>, e.g. -agentlib:hprof
  40. see also, -agentlib:jdwp=help and -agentlib:hprof=help
  41. -agentpath:<pathname>[=<options>]
  42. load native agent library by full pathname
  43. -javaagent:<jarpath>[=<options>]
  44. load Java programming language agent, see java.lang.instrument

p.s is this version of java j2sdk1.4.2 an old version. Should I update. The reason I say that is because I can't get the code for Scanner util to work and the graphics g
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Mar 31st, 2006
0

Re: compiling from command line

All you need to do is add the location of your javac program to the path variable of your computer. That way, you can execute javac from anywhere. Using this method, all you need to do is change to your project folder and execute "javac file.java". To add a location to your path variable, right-click My Computer, select Properties, select the Advanced tab, and select Environment Variables. There should be two path variables: one for your user and one for the system. If you use multiple users, add to the System path variable; otherwise, modify your User path variable. To add a location to the path variable, select path, click Edit, go to the end of the variable value, add a semi-colon (semi-colons seperate locations in the path variable), and add the location you want to add (c:\j2sdk1.4.2_04\bin in your case). After you click OK on all the dialog windows, close any remaining command windows, reopen them, and you now can access the programs in the "c:\j2sdk1.4.2_04\bin" folder from anywhere.

If you don't want to set the path variable, you can always compile by referring to the javac program by it's full name while in your project folder, such as:
Java Syntax (Toggle Plain Text)
  1. c:\j2sdk1.4.2_04\bin\javac hello.java
Reputation Points: 38
Solved Threads: 25
Posting Shark
chrisbliss18 is offline Offline
902 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: New to Netbeans and Slightly to Java
Next Thread in Java Forum Timeline: finding a class inside a jar file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC