Confluence - How to compile .java back into .class

javac ChartData1.java
ChartData1.java:51: error: class ChartData is public, should be declared in a file named ChartData.java
public class ChartData
^
ChartData1.java:9: error: package com.atlassian.core.util does not exist
import com.atlassian.core.util.DateUtils;

I’m already running the above in a java environment. Maybe the maven package needed to be loaded as well somehow ?

The issue is that your file ChartData1.java is declaring a class called ChartData (and not ChartData1). Either change your file name or your class name.

I got it to work but gets 13errors

javac -g -cp lib/atlassian-core-4.6.17.jar:lib/dom4j-1.6.1.jar:lib/joda-time-2.9.4.jar:lib/jfreechart-1.0.0.jar:lib/nekohtml-1.9.21.jar:lib/commons-lang-2.6.jar:lib/confluence-5.10.8.jar:lib/log4j-1.2.17.jar:lib/jcommon-1.0.0.jar:lib/xercesImpl-2.11.0-atlassian-01.jar ChartData.java
ChartData.java:146: error: incompatible types: Object cannot be converted to DateFormat
return this.dateFormats.get(index);
^
ChartData.java:229: error: incompatible types: Object cannot be converted to Element
final Element element = iterator.next();
^
ChartData.java:262: error: incompatible types: Object cannot be converted to Element
for (final Element e : element.elements()) {
^
ChartData.java:393: error: incompatible types: Object cannot be converted to Element
category2 = this.getFullText(this.headerList.get(0));
^
ChartData.java:397: error: cannot find symbol
if (ChartUtil.isVersion103Capable()) {
^
symbol: variable ChartUtil
location: class ChartData
ChartData.java:398: error: cannot find symbol
taskSeries = collection3.getSeries(category2);
^
symbol: method getSeries(String)
location: variable collection3 of type TaskSeriesCollection
ChartData.java:472: error: incompatible types: Object cannot be converted to Node
final Node node = i.next();
^
ChartData.java:491: error: cannot find symbol
return iterator.next().parse(value);
^
symbol: method parse(String)
location: class Object
ChartData.java:521: error: cannot find symbol
final Date date = iterator.next().parse(value);
^
symbol: method parse(String)
location: class Object
ChartData.java:559: error: cannot find symbol
final Attribute attribute = this.headerList.get(i).attribute(“title”);
^
symbol: method attribute(String)
location: class Object
ChartData.java:561: error: incompatible types: Object cannot be converted to Element
final String value = this.getFullText(this.headerList.get(i));
^
ChartData.java:596: error: incompatible types: Object cannot be converted to Element
final String elementText = ChartData.this.getFullText(this.list.get(i));
^
ChartData.java:603: error: incompatible types: Object cannot be converted to Element
final String elementText2 = ChartData.this.getFullText(this.list.get(i));
^
Note: ChartData.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
13 errors

Hi @fwoon,

Based on the “Object cannot be converted to x” errors you got, I assume you aren’t using generics in your iterators, lists, and collections. If this is indeed the case, either you cast them or use generics. Checking the errors you got:

ChartData.java:229: error: incompatible types: Object cannot be converted to Element
final Element element = iterator.next();

If iterator was initialized without generics, then you have to cast the object being returned by Iterator#next as an Element.

I believe it is the same with this error

symbol: method parse(String)
location: class Object
ChartData.java:521: error: cannot find symbol
final Date date = iterator.next().parse(value);

You might be expecting iterator.next() returns a Date object, hence, you used Date#parse, but without casting it as (Date) or using generics, it will be treated as an Object and Object class does not have a parse method.

Without seeing your entire class, these are mere assumptions based on the compilation errors you got.

Hope this helps.
Ian

FYI, this is the confluence chart plugin that comes default with confluence … so this is not something i develop from scratch…

Ok i sorted out all that and are left with 2 errors. It’s trying to use ChartUtil.java in the same folder as it is in (com/atlassian/confluence/extra/chart)
I’m running the compiling a level above (chart-plugin-3.0.1.mod/com/atlassian/confluence/extra/chart)

Shouldn’t the package declaration be enough in ChartData.java to access ChartUtil.java in the same folder like this:
package com.atlassian.confluence.extra.chart;

Errors:
chart-plugin-3.0.1.mod/com/atlassian/confluence/extra/chart/ChartData.java:404: error: cannot find symbol
if (ChartUtil.isVersion103Capable()) {
^
symbol: variable ChartUtil
location: class ChartData
[loading ZipFileIndexFileObject[lib/jfreechart-1.0.0.jar(org/jfree/data/gantt/GanttCategoryDataset.class)]]
[loading ZipFileIndexFileObject[lib/jfreechart-1.0.0.jar(org/jfree/data/category/IntervalCategoryDataset.class)]]
chart-plugin-3.0.1.mod/com/atlassian/confluence/extra/chart/ChartData.java:405: error: cannot find symbol
taskSeries = collection3.getSeries(category2);
^
symbol: method getSeries(String)
location: variable collection3 of type TaskSeriesCollection