I'm developing a scala library, which I would like to be used by java applications.
If I set up a java project in netbeans, with a reference to the scala library (jar), I can compile the java project without errors.
However I get problems when running the java project directly from netbeans (code from scala library is not executed e.g. for scala object methods), while when running it without ant (directly with java -jar .... on the command line in the /dist folder) everything works.
Does anyone have an idea why?
Boris
Without more information, it's impossible to say for sure. However, one possibility leaps immediately to mind: Your Scala library is using Scala types. If you don't have scala-library.jar in your Java programs' classpaths, they won't be able to use the Scala classes in your library.
Related
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.
I have a Java only project using Maven2. It'd be very useful to be able to get a REPL that has access to the full classpath of the compiled application and all libraries. In SBT, this is trivial for pure Scala and mixed Scala/Java projects: I run sbt console.
But it'd be very useful for pure Java projects too. I'm not bothered about what language: Scala, obviously, is pretty good for this, as is BeanShell, but JRuby or Jython or Rhino or Clojure would do the job pretty well too. Basically I want to be able to interactively poke and prod objects.
What's the simplest way to get a REPL set up in a Maven project without having BeanShell or Scala or whatever being added as a runtime/compile-time dependency?
For JRuby, try the following. Does not require modifying your POM.
mvn org.jruby.plugins:jruby-rake-plugin:irb
The GMaven plugin allows you to launch the groovy shell / console. This should have all the project dependencies in the classpath.
I am trying to recompile an existing Java project exported from Eclipse. It is necessary to recompile this because I am running simulations remotely on other machines where a different (older) version of Java is installed. I have tried recompiling my .java file which specifies the simulation in question. However, it appears that it is necessary to recompile all other classes etc as well. Has anyone got an idea how to do this WITHOUT using Eclipse (I am not the Admin on the other machines and thus Eclipse is unavailable to me) and not manually because the project is quite huge?
Thanks a lot for any suggestions!
I recommend you to always have an command line way to build an application. The usual way to do this in Java is using ANT (or Maven).
As #Santiago Lezica says, Eclipse can generate an Ant file.
I believe that Eclipse allows you to build for an older target platform than the one you are currently running. That way you can do all of your builds locally.
The second approach has the advantage that you can fix any problems arising from compiling for the older platforms (e.g. use of new language features, use of new classes / methods) from the comfort of your own ... workstation.
There is another option that you should consider: Tell Eclipse to generate code for the old Java version (see the compiler options). That way, you can create code that runs on Java 1.3, even if Eclipse uses Java 5.
Not sure what your requirements are, but you could set the compiler level for your projects at the (older) level of your Linux installs. This would cause Eclipse to recompile it at that version, instead of a newer version.
At my company we use IBM's Rational Application Developer (instead of pure Eclipse), but I am assuming the option is in the same spot. If you right-click on your project, you can go to the Java Compiler options and then set the compatibility to the level of that on Linux (1.3, 1.4, etc.).
Since compile Java byte-code is supposed to be portable (for the most part), this should get you past most of your problems.
Otherwise, the other option is to use something like Ant or Maven scripts (which can be kicked off by Eclipse) and then just use a property to set the compiler right before you run it. This way you don't have to switch properties on your projects all the time, if you truly do need "newer" compiled code and can't live with "older" code on both systems.
I have a java program consists of a jar for the "real program" and a sub-folder containing 20 jar library files (also have dependencies between them). I tried but without success ... I'm missing with the many options that gcj to compile :(. Does anyone know how to compile to native code so that a java program?
Thanks
Update: I have used the plugin for Eclipse (I'm using the 3.6 version of Eclipse and the plugin works well) http://gcjbuilder.sourceforge.net/ to generate a Makefile for the compilation. But now I have an another problem :(
Some libraries are not compiled (exit for error). The error is that GCJ considers all .class files inside .jar file, that have dependencies with other libraries do not exist. But for the purposes of my program, these classes are not used (that is, the java program it works properly). There is thus a way to force gcj to consider only the classes actually used in my java program?
I can only recommend that you don't use GCJ. It isn't Java. The compatiblity matrix on their web page is far from encouraging. It doesn't implement Java 1.2 completely yet, let alone all of 1.3, 1.4, 1.5, 1.6. The project appears to be falling further and further behind, and it never had 100% Java compatibility as a stated goal in the first place.
You may want to look at tools like autojar and firends to help resolve your dependencies and to make a single jar.
I want to develop a Java application mixing java with jython. I am using the IDE Netbeans with the python plugin. How do i work on this? (There is a built in support for Groovy with javaSE from IDE call Groovy classes from Java code, and Java classes from Groovy code but not for jython)
ref: http://www.netbeans.org/features/groovy/index.html
Netbeans 6.5 supports both Python and Jython.
http://www.netbeans.org/features/python/
Assuming you are using that version with the Python plug-in, it's just a matter of setting the runtime you wish to use via the platform manager (here's where you would choose Jython).
alt text http://img15.imageshack.us/img15/1586/platformmanager.png
I would also want to add that since 6.5 release, the Python bits have been vastly improved upon. So, if you want to try the new but unstable builds, please grab one from http://deadlock.netbeans.org/hudson/job/python/
Also, please refer to various documents linked from http://wiki.netbeans.org/Python and my blog posts at http://amitksaha.blogspot.com/search/label/nbpython
In case of problems, please let us know on the mailing list.
If you want to develop a Java application that blends with Jython and works outside NetBeans, then NB's ability to use Jython runtime doesn't help much. Instead, you have basically two choices:
You can compile your Python to Java classes using jythonc.
Or: you can embed the Jython interpreter inside your Java app.
To embed, you need to create a Jython library to be included in your Java app. Do this by going to Tools -> Libraries, select New Library, and add the stuff at NetBeans' Jython directory there (C:\Program Files\NetBeans 6.5\python1\jython-2.5 in my machine). You need jython.jar and at least most of the stuff at the javalib directory.