How do you compile .java back into .class
Asked by fwoon:

\> 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 ?


Answers:
author: Kurt Klinner
body: [@fwoon](/t5/user/viewprofilepage/user-id/247480)

Hi Francis

the first error comes due to the discrepancy between your filename and the name of the class.

Regarding the missing package, you need depending on how your are building your program either to adjust your classpath or to refer to the right maven repo

<https://mvnrepository.com/artifact/com.atlassian.core/atlassian-core/4.5.10>

Cheers

Kurt

comments: author: fwoon
body: Hi Kurt,

I managed to get it to work but got 13 errors.Seems like it needs to be run via atlas-mvn package ?

I was thinking do i really need to actually go thru atlas-create-confluence-plugin to create the plugin, put everything in and try to make it work so that atlas-mvn package works to package it into the jar that contains all the compiled .class ?

javac -g -cp lib/atlassian-core-5.0.9.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


author: Kurt Klinner
body: [@fwoon](/t5/user/viewprofilepage/user-id/247480)

Hi Francis,

without the source code it is quite hard to see why the incompatible types are mentioned. Could you share the source code?

Cheers

Kurt


author: fwoon
body: Hi Kurt,

This ChartData.java is the same ChartData.class that comes bundled with confluence.6.8.1 as chart-plugin.3.0.1.jar. I would love to attach it here but it's 600+ lines of code so....

Just abit of context :

I managed to decompile the original ChartData.class as ChartData.java...and tried to re-compile it back using the exact ChartData.java but failed. Subsequently i fixed all the errors due to generic.

Then i ran the javac command a level above chart-plugin-3.0.1.mod:

\> javac -g -verbose -cp lib/atlassian-core-5.0.9.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 chart-plugin-3.0.1.mod/com/atlassian/confluence/extra/chart/ChartData

Right now i am left with the last 2 errors due to the usage of ChartUtil.isVersion103Capable(). ChartUtil.java (which is also decompiled from ChartUtil.class) is in the same folder as ChartData in chart-plugin-3.0.1.mod/com/atlassian/confluence/extra/chart

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

I am starting to wonder if running javac is not the way to do this and instead create a confluence plugin via atlas-create plugin and try to somehow mimic all the file structure..since atlas-mvn package seems to convert all the .java to .class and package it into a jar file. However i tried that as well but ended up with like 22 errors that needs to be addressed.

It's hard to try to fix a atlassian error with just the .jar file w/o the actual project files


Tags: atl-dev

confluence-server

server