简体   繁体   English

使用多个.jar和javac

[英]Using multiple .jar with javac

pardon my terminology. 请原谅我的术语。 I'm trying to use three jar files with a java program for my CS class. 我正在尝试为我的CS类使用带有java程序的三个jar文件。 The first is funjava, a simplified java language, and the others are class definitions color and geometry. 第一个是funjava,一个简化的java语言,其他是类定义颜色和几何。 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. Circle的最后一个参数应该是colors.jar中的颜色,而不是字符串。

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. 如果要快速使用当前目录中的所有* .jar文件,并且使用的是JDK 6或更高版本,则可以使用单星号。 In a unix shell (like in Linux), you'll need to escape the asterisk: 在unix shell中(比如在Linux中),你需要转义星号:

javac -cp \* Canvas.java

This works when running the Java application as well: 这在运行Java应用程序时也有效:

java -cp .:\* Canvas

Note the .: to tell Java to look in the current directory as well as the *.jar files to find Canvas.class . 注意.:告诉Java查看当前目录以及* .jar文件以查找Canvas.class

On Windows, use a semicolon ( ; ) instead of a colon as a separator. 在Windows上,使用分号( ; )而不是冒号作为分隔符。

据我所知,-cp选项要求在大多数情况下将classpath指定为冒号或以冒号分隔的位置列表,而不是以扩展*.jar时操作系统似乎派生的逗号分隔列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM