Reputation: 83
I have a program that will not compile due to certain libraries not being found. I have tried using the -cp %pathTo\lib%/* command to include all .jar files. That gets it to compile but then when I try to run the program it tells me it cannot find or load the main class.
So I want to manually include each .jar file, my only problem is I don't know which exact ones to include.
/* ---------------------
* ThermometerDemo1.java
* ---------------------
* (C) Copyright 2002-2007, by Object Refinery Limited.
*
*/
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.ThermometerPlot;
import org.jfree.data.general.DefaultValueDataset;
import org.jfree.data.general.ValueDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleInsets;
/**
* A simple demonstration application showing how to create a thermometer.
*/
public class ThermDemo extends ApplicationFrame {
static class ContentPanel extends JPanel implements ChangeListener {
JSlider slider;
DefaultValueDataset dataset;
/**
* Default constructor.
*/
public ContentPanel() {
super(new BorderLayout());
this.slider = new JSlider(0, 100, 50);
this.slider.setPaintLabels(true);
this.slider.setPaintTicks(true);
this.slider.setMajorTickSpacing(25);
this.slider.addChangeListener(this);
add(this.slider, BorderLayout.SOUTH);
this.dataset = new DefaultValueDataset(this.slider.getValue());
add(new ChartPanel(createChart(this.dataset)));
}
private static JFreeChart createChart(ValueDataset dataset) {
ThermometerPlot plot = new ThermometerPlot(dataset);
JFreeChart chart = new JFreeChart(
"Thermometer Demo 1", // chart title
JFreeChart.DEFAULT_TITLE_FONT,
plot, // plot
true // no legend
);
plot.setInsets(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.setPadding(new RectangleInsets(10.0, 10.0, 10.0, 10.0));
plot.setThermometerStroke(new BasicStroke(2.0f));
plot.setThermometerPaint(Color.lightGray);
plot.setUnits(ThermometerPlot.UNITS_FAHRENHEIT);
plot.setGap(3);
return chart;
}
public void stateChanged(ChangeEvent e) {
this.dataset.setValue(new Integer(this.slider.getValue()));
}
}
/**
* Creates a new demo.
*
* @param title the frame title.
*/
public ThermDemo(String title) {
super(title);
JPanel chartPanel = createDemoPanel();
setContentPane(chartPanel);
}
/**
* Creates a panel for the demo (used by SuperDemo.java).
*
* @return A panel.
*/
public static JPanel createDemoPanel() {
return new ContentPanel();
}
/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) {
ThermDemo demo = new ThermDemo("Thermometer Demo 1");
demo.pack();
demo.setVisible(true);
}
}
Commands:
to compile: javac -cp B:\Programming\Java\Compiler\lib* ThermDemo.java
to run: java ThermDemo
After compiling there are two new files in my current directory. ThermDemo$ContentPanel.class, and ThermDemo.class
Upvotes: 0
Views: 120
Reputation: 719576
to compile: javac -cp B:\Programming\Java\Compiler\lib* ThermDemo.java
to run: java ThermDemo
Change that to:
java -cp .;B:\Programming\Java\Compiler\lib* ThermDemo
The runtime classpath needs to include (at least) all of the compile-time dependencies. The ".;" is needed to tell java
to look in the current directory as well ... to find the ".class" files you just compiled.
Actually, this solution only applies to your current problem. There is a lot of complexity in the way that classpaths work, and you would be advised to spend time reading up on it. Here's a good place to start:
(I'm assuming that ThermoDemo.java
has a main
method with the appropriate signature.)
Upvotes: 2
Reputation: 1
ThermDemo.class
is the class that you have to run. ThermDemo$ContentPanel.class
is the inner class. When you compile a class having inner classes, both class files will be generated.
Upvotes: 0