I need to batch a compilation with a special JRE which has been "customized".
Eclipse is able to compile the classes with this JRE, but I need to make a build script outside of Eclipse.
What is the method used by Eclipse to generate the .class files without a JDK?
Eclipse comes with its own compiler for the following reasons:
Incremental compilation (can compile just the changed parts of the project which can mean more than the amount of files you just saved, for example, when you changed some global)
The Eclipse compiler can create a class file even when the code contains errors. This allows to run the project even though not everything compiles.
The compiler provides Eclipse with an AST so it can do all kinds of fancy stuff (like the outline, show you all the places where the variable under the cursor is used, etc) at no extra cost (i.e. it doesn't have to run the compiler and another parser).
I believe Eclipse comes with internal compilers, and you can choose the compatibility to Java 1.3 through 1.6 (check the Preferences menu, under Java->Compiler). So Eclipse doesn't need an external JDK to compile, because it comes with it is self-sufficient.
If you want to create a build script outside of Eclipse, you're gonna need an external compiler, like the one that comes with the real JDK.
For the case one is interested: Eclipse's compiler is part of JDT core.
Eclipse was originally created by IBM. Eclipse has its own built-in Java compiler which is based on IBM's Java compiler, Jikes.
Related
I am trying to set a breakpoint in a Scala Macro implementation using the Eclipse IDE and failing
Firstly: Scala Macros Rock! Up to now I have preferred Clojure to Scala, but with macros I'm no longer sure
I'm trying to create a macro that will return the toString of a function and the function itself. When that works I'm going to make a new function with a sensible toString. Ah happy days.
But I need to be able to debug the macros. I use Eclipse (20110615-0604), with Scala (2.10.1). I downloaded the scala-compiler-2.10.1.jar and the code from http://www.warski.org/blog/2012/12/starting-with-scala-macros-a-short-tutorial/ now works. I've written a couple of simple macros as well. The macros are in an eclipse project "ScalaMacro" and the code that uses them is in a separate project "HelloScalaMacro"
I'd now like to debug them
Following the instructions at http://docs.scala-lang.org/overviews/macros/overview.html I have created a runtime configuration with scala.tools.nsc.Main as the entry point. I've added -cp HelloScala.scala, and when I run the configuration it actually seems to compile the code (if I put errors in, it reports the errors correctly).
Unfortunately the instructions imply that a breakpoint in the macro implementation should cause Eclipse to pause. It doesn't.
I've done the usual: google search for Eclipse/Scala macro/Debug/Breakpoint, read all the stackoverflow questions in the scala-macro tag, and played around a lot with every eclipse setting I can find.
So if any of you out there know how to set breakpoints, could you let me know how: is it an eclipse version / scala version / ... issue?
I haven't tried this myself, and in principle it is as likely (or more likely) to fail as what you've already tried, but if successful it could be more convenient to you.
To try this you should have Scala-IDE along with the source feature installed. Make sure you are working off of an Eclipse installation that is either "Eclipse Classic", "Eclipse for RCP Developers", or a similar concoction you came up with on your own.
You will also want to install the Equinox Weaving Launcher plugin, that will allow you to create an "Eclipse Application with Equinox Weaving" launchers.
Now:
Create a new workspace
Create a Scala project
Plant your macro code in that project
Add a break point in the macro source
Getting ready to debug:
Create a new "Eclipse Application with Equinox Weaving" debug launch configuration. Give a name more elegant than "New_configuration".
under "location", point it towards a new different workspace directory
under the "configuration" tab, provide something like "-Xmx1536m"
By default, all plugins available to your running Eclipse instance should be available to the instance you are about to launch. Eclipse may need some cajoling in order to include a non-plugin project in the classpath -- if this doesn't work, that's the first thing I'd try to look at.
You will now want to launch the debug configuration.
Depending on your Scala-IDE version, you may encounter a "Multiple launchers available -- Select one..." warning. I'd go for "Equinox Weaving enabled Eclipse Application Launcher".
Once inside the Eclipse instance being debugged:
Create the project you want to use the macro
Make sure to add a dependency on the binary output
Add a small usage example of your macro to the project in the workspace being debugged.
Cross your fingers
Build
In theory, the launching Eclipse instance will now pause the instance being debugged on your break point.
The instructions given by Nadavwr (just below) were helpful, and I recommend them to other people.
The key solution for me was to realise that there are two projects involved, the project that defines the macro, and the project that uses the macro. Rather foolishly I was trying to debug the project that defined the macro
So the instructions as given in the documentation are correct, I just had to make sure I was running them in the correct project: obvious of course.
For the benefit of other people, I found it very helpful to use a command line scalac to get the command line correct: much quicker editing that, and controlling which directory I was in, then in eclipse
The other thing to realise for people thinking of using Scala Macros are that the error messages from running scalac directly are MUCH better than those from eclipse.
Part of a project I'm on has a GUI app that is built with Netbeans using the GUI design tools that come in that IDE.
But this is only part of a bigger project, and needs to be built in an environment that does not have Netbeans installed (it happens to be a Gradle-based build on Jenkins). I've gotten builds to (seemingly) work, but keep running into inexplicable run-time errors (i.e., dependencies appear to be met with identical jars on the classpath and so on, but attempts to read resources from the project jar fail.).
From googling around, it looks like this might have something to do with compiling .form files and then including some dependency for the resulting java. (though, the Netbeans build does not add any jars above what our gradle build adds).
So the question is... can this even be done? or does a proper build simply rely on some hidden build-time mojo that's going on in Netbeans?
Yes, you can compile the classes without NetBeans. Just be sure you do not any NetBeans library, like AbsoluteLayout. The .form files are for NetBeans showing you components with Matisse, but all the generated code will be in the .java file.
This question is not limited to lex and yacc, but how can I add a custom script compiler as part of a project? For example, I have the following files in the project:
grammar.y
grammar.l
test.script
The binary 'script_compiler' will be generated using grammar.y and grammar.l compiled by lex, yacc and g++. And then I want to use that generated script_compiler to compile test.script to generate CompiledScript.java. This file should be compiled along with the rest of the java files in the project. This setting is possible with XCode or make, but is it also possible with Eclipse alone? If not, how about together with Maven plugin?
(I might setup the script compiler as a separate project, but it would be nice if they can be put in the same project so that changes to the grammar files can be applied immediately)
Thanks in advance for your help!
You can add a custom "Builder" from the project properties dialog. This can be an ant script (with an optional target) or any other script or executable.
There are also maven plugins for ant and other scripting languages
If you just want to run an external program in Maven this is what you want: http://mojo.codehaus.org/exec-maven-plugin/ -- you can then run Maven targets from your IDE or command line and it should do the right thing either way.
To integrate with the normal compilation bind the plugin to the "generate-sources" phase and add the location where the Java files are generated to the "sourceRoot" option of the exec plugin. That way the compiler will pick them up.
Ideally you generate the code into a folder "target/generated-sources/MY_SCRIPT_NAME". That is the standard location for generated sources in the Maven world and e.g. IntelliJ IDEA will pick up source files inside of that location. Note that this doesn't work if the files are directly in "target/generated-sources".
The other option is to write your own Maven plugin, which is actually quite easy as well. See e.g. https://github.com/peterbecker/maven-code-generator
This is getting to me a bit.
What should be a straightforward and well worn procedure to do something all users need to do is anything but straightforward.
I made the Java class I want to add to all new Java projects into a JAR file.
And I got it into the JRE folder using Window > Prefs > Java > Installed JREs, etc.
But come runtime, the Java interpreter just doesn't see this class as attached to my projects.
Anyone know how this pesky one is fixed ?
I'm using Eclipse 3.6.2 Helios and JRE 7.
The JRE isn't really intended to be extended in this way. If you must store your shared libraries in the JRE, the ext folder should be used, rather than the top-level JRE folder. However, even this is usually a bad practice: Is putting external jars in the JAVA_HOME/lib/ext directory a bad thing?.
To add dependencies to your Eclipse projects, use the project's build path. To add dependencies at run-time, use the Java class path.
I would create a userlibrary and add the lib to the project setup. http://goo.gl/pEoto
Consider to use Maven to manage your dependencies.
I have a project in Eclipse that currently has no ANT build file, but is about to have one created (to facilitate building jars). I'd like to write the build file so that it would work for both. I was just going to write the full build in ANT but I noticed this line in an IBM Help doc.
The Java builder runs the internal
Eclipse Java compiler which in turn is
responsible for indexing your source
so that searching, refactoring and
many other features are available.
Thus it is not possible to replace the
internal Eclipse Java compiler by
using a project builder. You can
disable the Java builder and you can
control when the Java Builder runs
with respect to the project builders
that you define.
Do I need to write the ANT file so that it conditionally compiles (javac) only outside Eclipse? Are there other things I need to do to make ANT and Eclipse play nicely together?
There are maybe more sophisticated approaches, but here's what works for me. Just set up your Java project in Eclipse to output classes to the same dir as your Ant buildfile does. Let Eclipse compile your project using normal Java compiler.
During typical development, you will probably be changing Java source files and wanting to see that they compile. The Eclipse Java compiler will take care of this. Less frequently you will need to rebuild jars. Ant will take care of that. You can kick off the Ant build when you need to from the command line or from Eclipse.