使用多个.jar和javac [英] Using multiple .jar with javac
问题描述
import colors。*;
class Canvas {
public static void main(String [] args){
System.out.println(test123);
Circle cr1 = new Circle(new Posn(1,2),5,blue);
Circle cr2 = new Circle(新Posn(5,4),3,red);
}
}
class Circle {
Posn center;
int rad;
字符串颜色;
Circle(Posn p,int r,String c){
this.center = p;
this.rad = r;
this.color = c;
}
}
类Posn {
int x;
int y;
Posn(int x,int y){
this.x = x;
this.y = y;
}
}
Circle的最后一个参数应该是colors.jar中的颜色,而不是字符串。
niko @ niko-laptop:〜/ Classes / Fundies2 $ javac - cp * .jar Canvas.java
错误:类名称'funjava.jar,geometry.jar'仅在明确请求注释处理时才被接受
1错误
niko @ niko-laptop :〜/ Classes / Fundies2 $ ls
1-20-10.java 1-21-10.java Book.class Canvas.class Circle.java Examples.class funjava.jar hw1~Main.java OceanWorld.java
1-21-10 Author.class book.java Canvas.java colors.jar Examples.java geometry.jar Ishape OceanWorld Posn.class
1-21-10~Partue.java Book.java Circle.class Combo.java Fundies2.txt hw1 Main.class OceanWorld~Rect.java
那么我该如何明确请求注释处理?
谢谢。
除了 Romain Muller 的回答:
如果要快速使用当前目录中的所有* .jar文件,并且使用的是JDK 6或更高版本,则可以使用单星号。在unix shell中(比如在Linux中),你需要转义星号:
javac -cp \ * Canvas .java
这也适用于运行Java应用程序:
java -cp。:\ * Canvas
注意。:
告诉Java查看当前目录以及* .jar文件以查找 Canvas.class
。
在Windows上,使用分号(;
)而不是冒号作为分隔符。
pardon my terminology. I'm trying to use three jar files with a java program for my CS class. The first is funjava, a simplified java language, and the others are class definitions color and geometry. Here is my code and what happens when I try to run it.
import colors.*;
class Canvas{
public static void main(String [] args){
System.out.println("test123");
Circle cr1 = new Circle( new Posn(1,2), 5, "blue");
Circle cr2 = new Circle( new Posn(5,4), 3, "red");
}
}
class Circle{
Posn center;
int rad;
String color;
Circle(Posn p, int r, String c){
this.center = p;
this.rad = r;
this.color = c;
}
}
class Posn{
int x;
int y;
Posn(int x, int y){
this.x = x;
this.y = y;
}
}
The last argument of Circle should be a color from the colors.jar, not a string.
niko@niko-laptop:~/Classes/Fundies2$ javac -cp *.jar Canvas.java
error: Class names, 'funjava.jar,geometry.jar', are only accepted if annotation processing is explicitly requested
1 error
niko@niko-laptop:~/Classes/Fundies2$ ls
1-20-10.java 1-21-10.java Book.class Canvas.class Circle.java Examples.class funjava.jar hw1~ Main.java OceanWorld.java
1-21-10 Author.class book.java Canvas.java colors.jar Examples.java geometry.jar Ishape OceanWorld Posn.class
1-21-10~ Author.java Book.java Circle.class Combo.java Fundies2.txt hw1 Main.class OceanWorld~ Rect.java
So how do I explicitly request annotation processing? Thank you.
In addition to Romain Muller's answer:
If you want to quickly use all of the *.jar files in the current directory, and you're using JDK 6 or later, you can use a single-asterisk. In a unix shell (like in Linux), you'll need to escape the asterisk:
javac -cp \* Canvas.java
This works when running the Java application as well:
java -cp .:\* Canvas
Note the .:
to tell Java to look in the current directory as well as the *.jar files to find Canvas.class
.
On Windows, use a semicolon (;
) instead of a colon as a separator.
这篇关于使用多个.jar和javac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!