Compile complex Java Program in native code using GCJ - java

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.

Related

How its possible for eclipse to compile and run programs on JRE without JDK [duplicate]

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.

Eclipse build succeeding but command line giving 'code too large' error

I'm facing a very silly problem.
If I build my project using the Eclipse UI, it builds and runs fine. However, if I build it on the command-line using the plain old javac (i.e., without any ant or maven build tool), I get a code too large error on one of the files (which, btw, happens to be a Antlr3-generated Java parser file).
What's strange is:
My Eclipse project is pointing to the same JDK that I'm using on the command-line! So, it is not the case that I'm inadvertently using built-in Eclipse Java compiler
If the parser code were really 'too large' (some method in it being > 64K), why isn't the Eclipse build resulting in the same error? For this very reason, I'm also reluctant to start tweaking my parser grammar - a much more involved task.
I'm using Eclipse Neon and Oracle JDK 1.8.
The Eclipse UI always uses the Eclipse Java compiler, it never uses javac. So it may be the Eclipse compiler is doing a better job in this case.
The installed JRE is used for the libraries and the JVM when you are testing. Eclipse always uses its own compiler since it needs to do incremental compilation which javac can't do.

Can I develop Java programs if I have only JRE installed?

I have JRE 1.7 installed on my system. Due to some admin issues I don't have JDK on my system. is there any way I can develop Java programs with JRE only?
No you can't develop java programs only with JRE
You will need JDK for compiling your programs.JRE provides only runtime environment,but JDK is something you will need to compile your code to make them executable by your JRE.You will need javac for compiling your code which is present in JDK.
However for resolving the issue of admin rights you are having, you can download and install eclipse which has its own built in compiler.
You need some program which compiles your sources, but that doesn't neccessarily have to be the JDK.
For example you can download Eclipse which only requires a JRE, it has it's own compiler (built-in) and you can develop with that. Eclipse does not require any admin priviliges, it's a zip file which you can download and extract.
You need to compile them in order to develop and that is why you need jdk
You can't develop any Java application since you need JDK(Java Development Kit) to compile your code. JRE(Java Runtime Environment) provides run time environment only. You can run your compiled code in JRE.
the answer is somehow "yes,but..."
java source code execution procedure is split into 2 steps :
1)compiling the source code into a byte-code,thus generating the .class file
2)interpreting the VM specific instructions from the .class file into native instructions
.java----javac---->.class----java---->native code
needless to mention that the "javac" , the compiler of the java source code is in not part of the JRE!
so in order to develop java programs without JDK you have to skip the first step and keep using exclusively the "java" tool,thus dealing directly with byte-code !
in some extent and if you're acquainted with the JVM internals,it's possible to write some lines of byte-code using hex or text editors and then running the .class file;but you will not go further then that specially when it comes to creating complex applications as this require super-human capabilities :that's a highly daunting task .
nevertheless,todays java frameworks almost all use direct byte-code manipulation and tools like the asm framework or javassit
javassist does not require the JDK and you can generate a class from scratch and then compile/run it
java -classpath .:javassist-x.x.jar test "some arguments"
(no need to compile classes)
but again,that is only for restricted use and in order to develop java applications you have to use some JDK...
finally,you have to strive to acquire full control upon what is running in you machine;recent frameworks are resource-greedy and needs a huge amount of resources(disk space,memory...) and many tools and framworks require full control,i mean administrator right : for instance i remember that once a time borland delphi refused to start and i had to give it full access rights to start...
I request you to resolve admin rights. Else I have two options for you.
1) You cannot do anything without Java Development Kit.
2)You can install a IDE to code Java which makes your work in the current situation simpler. Use Eclipse or NetBeans. I would recommend Eclipse to you anyway. You can download eclipse from this link https://www.eclipse.org/downloads/
Try downloading JDK from this http://www.oracle.com/technetwork/java/javase/overview/index-jsp-138218.html.
Hope this helps you.
JDK is needed to compile your java file into class file. And JRE will execute the generated class file and provides the output.
If you have admin problems in your m/c then you can install the JDK in some other m/c and take the class files into your system and execute them.
Eclipse includes its own compiler and doesn't depend on the JDK compiler. But indeed, the JRE is just the runtime environment and doesn't include the compiler or other development tools.
Do you need this to do you job or not? If it's your job, you should have access or they should install it. If you don't have access because it's not your job, I suggest installing the JDK at home (or on a laptop you can take with you)
Due to some admin issues I don't have JDK on my system.
Install it in your home directory or another directory you can write to. Your admins can't prevent you from installing the JDK if you have enough disk space.
JRE is not just sufficient, without compiling the code for that you need Jdk which have compiler to compile the code.

Java compilation problem, Linux, project from Eclipse re-compile on Linux

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.

using scala jar from java project in NetBeans

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.

Categories