Using multiple .jar with javac

Have mercy on my terminology. I am trying to use three jar files with a java program for my CS class. The first is funjava, a simplified Java language, while the others are color and geometry class definitions. 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 to Circle should be the color from colors.jar, not the 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 can I explicitly handle annotations? Thanks.

+4
source share
2 answers

In addition to Romain Muller's answer:

If you want to quickly use all * .jar files in the current directory and use JDK 6 or later, you can use an asterisk. In a unix shell (for example, on Linux) you will need to avoid the asterisk:

 javac -cp \* Canvas.java 

This works when starting a Java application:

 java -cp .:\* Canvas 

Pay attention to .: To tell Java to search in the current directory, as well as in * .jar files to find Canvas.class .

On Windows, use a semicolon ( ; ) instead of a colon as a separator.

+17
source

As far as I know, the -cp option requires that the classpath be specified as a list of places separated by colons or semitones, in most situations, and not a comma-separated list, since your OS seems to be generated when the *.jar extension is used.

+2
source

Source: https://habr.com/ru/post/1299489/


All Articles