Reputation: 6061
I have few java files. Main.java
uses Picture
class from Picture.java
file. I want to know how to compile and run Main from command line ?
Here is Main.java
:
package com.company;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class Main {
static Picture pic = null; // Picture class ???
public static void main(String[] args) {
long t1, t2;
String name = "bears.jpg";
pic = new Picture(name);
t1 = System.nanoTime();
pic.new_img = meanFilter(pic.img);
t2 = System.nanoTime();
pic.writeImage();
calculateTime(t1, t2);
}
and Picture.java
:
...
public class Picture {
public BufferedImage img;
public BufferedImage new_img;
...
Upvotes: 1
Views: 2753
Reputation: 17
You need to specify the whole package.
Try running this:
javac com.company.Picture.java com.company.Main.java
Upvotes: 1
Reputation: 15423
Assuming both classes are in the same directory use :
javac Picture.java Main.java
This way the dependent class (Picture.java
) is compiled first before your Main.java
To run it you will need to specify the entire package structure and run it from the src
directory :
java com.company.Main
Upvotes: 4