如何编译java代码? [英] How to compile java code?

查看:40
本文介绍了如何编译java代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆 java 文件,我正在运行以下代码以尝试编译它们.

I have a bunch of java files and I am running the following code in an attempt to compile them.

"Program FilesJavajdk1.6.0_16injavac" Main.java

我看到了这个错误信息

Main.java:3: package colourtiler.patternsdoes not exist 
import colourtiler.patterns.draw;

它所指的代码位于文件夹 patters/PatternColour.java 中,我怎样才能让它包含这个文件?

The code it isreferring to is located in the folder patters/PatternColour.java, how can I get it to include this file?

谢谢

推荐答案

您需要在 javac/java 的 -cp-classpath 参数中包含其路径.例如

You need to include its path in the javac/java's -cp or -classpath argument. E.g.

javac -cp .;c:/path/to/colourtiler/patterns/draw Main.java

其中 c:/path/to/colourtiler/patterns/draw 指向依赖类的包根.如果您有更多,则需要用分号分隔.如果路径中有空格,则需要引用单个路径.或者,您也可以将其打包到 JAR 文件中(或使用已打包的文件)并将 JAR 文件的完整文件路径放在类路径中.

where c:/path/to/colourtiler/patterns/draw points to the package root of the dependency classes. If you have more, then you need to separate it by semicolon. If there are spaces in path, you need to quote the individual path. Alternatively you can also package it in a JAR file (or use an already packed one) and put the full file path to the JAR file in the classpath.

如果收集和输入类路径很无聊,请考虑使用批处理/shell 文件.

If gathering and typing the classpath get bored, consider using a batch/shell file.

祝你好运.

这篇关于如何编译java代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆