looking for java syntax open source compiler (not sun jdk)

do you know some (written in java) java syntax compiler, and i am not talking about jdk, but some open source compiler that could be able to compile java code to bytecode.
I have found some intresting projects like for example:
http://jakarta.apache.org/bcel/
http://jikes.sourceforge.net/
https://jen.dev.java.net/

but first and third are good when i am programming with bytecode instruction by myself (in this way i am using jasmin but those are also good), and only second provide direct syntax compilation but it is written as native code(C++) not in java

so again i am looking for some java compiler (that compiles .java files not directly bytecode like bcel) which is written in JAVA, can anyone help please?

GCJ?

well yes it is laso good and intresting but it is made as native program available for windows and linux, i was thinking about some program compiled into java code not native
windows or other…

thanx anyway, i was also thinking about beanshell becouse it is made in pure java and it is quite small but i found in faq http://www.beanshell.org/intro.html that it is interpretated not dynamicly compiled, i am looking for prog that will analize java lexical/syntax and will produce bytecode from itself…

Kaffe or blackdown might be worth a look. Both are only available for linux though, but they will compile to java byte code.

HTH

Endolf

ok so it was my mistake , maybe i do not provide you enough information what i want and what i would like to use it for.

I am making some program in java that would be able to create applets and also java executable programs, this program will be genearlly focused on graphics2d/3d sound using mp3 etc. People who will use ths program would be able to create their custom animations in 3d or 2d and this process will be as simple as possible for example like in 3dmax or very popular swift 3d(which can create 3d animations described in flash swf format files), it also will be able to make applet menus, customized buttons etc, the generall idea is to make it as easy to use as it is possible (this program will be for webmasters not programers).
But i would like in the near future add some posibility to extend this program by users using java classes, something similiar to scripts (like for example actionscript in flash), i thought about beanshell but it is a true script interpreter without direct bytecode compilation. I need some compiler that would be able to generate java code (from .java files) into bytecode/.class files. I could add sun jdk to my program, so users will not have to have their own compiler but it will be to heavy (more than 20mb) so i wolud like to find a compiler that i colud add to my program, i will make some simple IDE where users will be able to write their java code (using swing DefaultEditorKit class), but THOSE clasess will must be compiled to java bytecode. Theoreticaly i could make that compiler on my own using javacc(lexical/syntax analizer etc) and than using jasmin or jen to compile it into bytecode but it is too much work, i have never written a compiler at all. I know binary form of java files - instructions etc, but i think that there must be somewhere in the internet some free java compiler to use.

And how i imagine use of this kind compiler ? like this:

  1. Lets imagine that i have some button class that i created on my own during developing my program:

public abstract button{
public abstract void draw();
}

class is compiled and used by program to draw button when it is necessary, i can make my own implementation of this class like this:
public class greanButton extends button{
void draw(){
… some graphics operations
}
}

and during executin this greaButton class can be used as follows:

button _button1 = ( button )myClassLoader.loadClass( “greanButton” ).newInstance();
_button1.draw();

so i really do not have to know how drawing of button is implemented becouse i have abstract class

  1. Second let’s imagine a user that would like to make his own implemetation of button class, becouse he would like to make his own rendering of it, he can use a sun jdk to compile his customized button class on his own and add this into my program , but he would have to have his own jdk or any other similiar compiler. BUT i do not want to make it in this way i would like to integreate some java compiler to my program. Also IDE will be included user would be able to make java classes, cheange them etc,
    those classes will be compiled and used as in above code. This is the reason why i am looking for crossplatform java compiler which is written in java and can be used in my project . That program also will be crossplatform with no native libs (except jogl, ode). I could use beanshell but it is not what i am looking for. I am loking for complier that will generate a .class file from for example greanButton.java file, i am not lokking java virtual machine or specyfic compilers from java to windows/linux etc.

So please anyone who are not bored this topic, have you got any ideas

Can’t you invoke the sun compiler from Java? I don’t mean with Process.exec(), I mean call the compiler classes directly. In fact I thought there was some work in this area recently… maybe for Mustang.

invoking compiler from java ? what do you mean i found only java.lang.compiler class which i think it is not useful for anything and in mustang there is javax.script but this is collection of interfaces for scripting languages also not useful for me

I think swpalmer was talking about this. As long as the end user is using the jre from the sun JDK already installed on thier system to run your code it would work, but it does rely on that fact. No sun JDK = ClassDefNotFoundExceptions when you try the compile.

Endolf

you are very helpful endolf, but it wil work as the same if i used Process.exec() and calling javac, i was thinking about something that is not a part of any jdk, i do not nead
a heavy package like jdk but some light written in java compiler, well thanx again for your time, anyway i will look in the internet , if anyone will find something please describe it in this topic.

Yup

I couldn’t find anthing ready, but you might be able to ‘borrow’ bits from the compiler from blackdown or kaffe, and distribute that as a seperate component. You will need to make that one bit GPL though as kaffe and blackdown are I think (if you can even get the source for them). You will then be able to ship that with your project too. I’m not sure how they would work with say swing. I’ve not used them for years, and as runtimes go, I was disapointed by kaffe, and I don’t think blackdown had swing.

They might be options to investigate though.

HTH

Endolf

I could add sun jdk to my program, so users will not have to have their own compiler but it will be to heavy (more
than 20mb)

You only need that tools.jar (compressed its ~2mb) for using the compiler.

Except you arn’t allowed to by the sun license. :frowning:

Endolf

java gaming comunity is the best, thanx you all especially you endolf for link to kaffe and blackdown.
Generally kaffe is virtual machine but i looked at this site again and in the links sections i found many useful links and even much more that i expected there are lots of compilers i was thinking for example:
http://kiev.forestro.com/ - now site is not working but in future maybe, downloads can be found in google
http://www.eclipse.org/ - well it appears that it has it’s own built in compiler
http://nice.sourceforge.net/ - it is a nice language extended java language
http://pizzacompiler.sourceforge.net/ - last update is from 2002, also extends java language

other can be found at this site:
http://www.thefreecountry.com/compilers/java.shtml - many useful opensource project links, probably everything you would like to have
http://www.mathtools.net/Java/Compilers/ - registration required, collection of compilers links

AND NOW FRIENDS SOMETHIGN SPECIAL

www.janino.net - it is more than simple compiler, written in pure java, quite small jar is 359 kb, in January 18, 2006 new version was released (Version 2.3.17) with many features, and for me the most exciting things:

http://www.janino.net/javadoc/org/codehaus/janino/ExpressionEvaluator.html - expression evaluator, write expression as simple string and evaluat it !!! for example

  // Compile the expression once; relatively slow.  - code example from the above site
  ExpressionEvaluator ee = new ExpressionEvaluator(
      "c > d ? c : d",                     // expression
      int.class,                           // expressionType
      new String[] { "c", "d" },           // parameterNames
      new Class[] { int.class, int.class } // parameterTypes
  );

  // Evaluate it with varying parameter values; very fast.
  Integer res = (Integer) ee.evaluate(
      new Object[] {          // parameterValues
          new Integer(10),
          new Integer(11),
      }
  );
  System.out.println("res = " + res);

compilation of this expression took about 670 microseconds on machine (2 GHz P4) and evaluation 0.35 microseconds (2000x faster than compilation)
i did not expect that some kind of expression dynamicly compiler and evaluator exist , what a power!

another example:
janino sourceClassLoader, generally classLoaders are loading .class files, but janino can load, dynamic compile to bytecode .java files and return as true classes to the jvm, that can be used as in my example (greanButton etc) check it out at
http://www.janino.net/javadoc/org/codehaus/janino/JavaSourceClassLoader.html
We really do not nead to use beanshell or any other scriptengine, users can make their java code even in notepad and this classloader will compile it, No JDK required
also it can be used as command line compiler, it can be used with ant, tomcat, and you can also analyze java code using it

this is what i wanted, this is even more that i expeced, this is the best thing i recently founded

again thanx to all users for their patience especialy endolf , onyx (2mb->i checked it not for me), bleb and swplmer

Janino is good, but it fails on larger java files for some reason…

I suggest JDT (its the compiler that eclipse uses), its seriously seriously fast…

(google for it)

DP

Hmm yea janino. I used it for a while in the past and thanks to me a handful of bugs were fixed (they are very responsive), but it tends to blow randomly up after the code got big enough (500+ lines of operator heavy code). Eventually that was fixed in the meantime.

I think its about time to re-evaluate it.

http://www.eclipse.org/jdt/ - yeah i will try it it seams to be better than other thanx you guys

for those who would like also to use it please folow this link:
http://dev.eclipse.org/viewcvs/index.cgi/jdt-core-home/howto/batch%20compile/batchCompile.html?rev=1.4

for compilation of java classes only org.eclipse.jdt.core_3.1.1.jar (or newear) is important , this file is about 3,5 mb so it is not so bad
but after obfuscating and shrinking etc using proguard compiler is only 580 kb!!! - and it is full functional i compiled my applet using it and works fine, this is what i nead

And so I did. Heh.

I used it for the last 2 weeks for prototyping all kinds of things all day long. AFAICT compilation is a bit slower now (still way faster than javac - it only takes a splitsecond), but it seems to be more robust now. I didnt had any random screwups with the latest version.

thanx onyx i will check it today