Compiling java from the command line
I am try开发者_Python百科ing to compile an application from the command line
The programme compiles and runs fine in eclipse, howvever when i goto the command line and use javac to compile my java file i get 23 errors, the majority of which are Cannot Find Symbol, with an arrow pointing to the . in a package name.
Does anyone have any ideas on what i need to do differently?
Thanks
Your classpath is not set up correctly. Look at your Eclipse project in the .classpath file. In there you will find a lot of classpathentry elements. You will need to replicate this for your command line compilation.
To do this manually you must first set your CLASSPATH environment variable to a list of directories (or jar files) containing class definitions.
You can also use a build tool called ant to automate this for you.
I advise against setting the classpath as an environment variable because it is too intrusive (all your java programs will see it).
A command line for compiling a Java app which dependes on Log4j might look like this:
javac -cp C:\dev\mvn\repo\log4j\log4j\1.2.16\log4j-1.2.16.jar AppenderTester.java
If you have multiple classpath entries you need to separate them with a semicolon.
For ease of use you could create a startup script. This can be a simple batch script or a more elaborate ant script (which requires installing ant).
This is only the tip of the iceberg known as 'classpath hell'.
EDIT: you can also take a look at the Eclipse feature 'export runnable JAR', which packs your application together with all its dependencies in a JAR file.
精彩评论