Jni4Net with different JDK's - jni4net

I am building C# proxies for Java classes (using proxygen.xml) and my question is: can Jni4Net compile .java files using different JDK than saved in JAVA_HOME variable? Or do I need to change it temporary?
Thanks

Jni4Net uses the JAVA_HOME path, so the easiest option in your case is to change it temporarily.

Related

JAVA_HOME or PATH or BOTH?

I was watching the Android development video and they asked us to install JDK and create JAVA_HOME environment variable.
I already have MyEclipse installed and I previously had setup the PATH variable(giving it the directory of JDK), do I still need a JAVA_HOME variable ??? If yes then why ???
Yes, you do need.
PATH is usually used to lookup the executables so that you haven't to specify the whole path to execute. JAVA_HOME may be used by the scripts or IDEs to lookup libraries. You can specify JAVA_HOME and build path variable basing on it. E.g (depending on OS)
PATH=$PATH;$JAVA_HOME/bin
Short answer, YES, you do need to set JAVA_HOME.
You can read here the difference between each one of them, but I'm pasting the explanations below as well:
JAVA_HOME and JRE_HOME are not used by Java itself. Some third-party programs (for example Apache Tomcat) expect one of these environment variables to be set to the installation directory of the JDK or JRE. If you are not using software that requires them, you do not need to set JAVA_HOME and JRE_HOME.
CLASSPATH is an environment variable which contains a list of directories and / or JAR files, which Java will look through when it searches for Java classes to load. You do not normally need to set the CLASSPATH environment variable. Instead of using this environment variable, you can use the -cp or -classpath option on the command line when using the javac and java commands.
PATH is an environment variable used by the operating system (Windows, Mac OS X, Linux) where it will look for native executable programs to run. You should add the bin subdirectory of your JDK installation directory to the PATH, so that you can use the javac and java commands and other JDK tools in a command prompt window. The JDK installation instructions explain how to set PATH.
If the application you are using is looking for a specific dataset in the JAVA_HOME environment variable and it isn't there, it is not going to be happy.
Other applications might look for the JDK path in the PATH environment variable, but just because you have it there doesn't mean it will work for other applications that need it in a separate variable.

Dart Editor: It didnt work?

I launched Dart Editor yesterday but it didn't work giving the error:
("A Java Runtime(jre) or Java Development Kit(jdk) must be avaible in
order to run DartEditor. No Java virtual machine was found after
searching the following loacations:
C:\Users\name\Donwloads\darteditor-windows-x64\dart\jre\bin\javaw.exe
jawaw.exe in your current PATH ")
Do you think how i going to fix this error ?
Thanks
Checkout this link:
https://www.dartlang.org/tools/editor/troubleshoot.html
"Launching Dart Editor"
Your Java version should have the same bit width as your Dart Editor version. For example, if you're using a 64-bit Dart Editor, then you should use 64-bit Java. Otherwise, you might see a message like this when you try to launch Dart Editor:
Failed to load the JNI shared library "C:\Program Files(x86)\Java\jre6\\bin\client\jvm.dll
To determine which version of Java you are running, do one of the following:
1-Go to CMD type java -version.
2-Go to Start -> Programs and Features.
Specifying the Java runtime
If necessary, you can specify the Java runtime that Dart Editor uses. Go to your Dart installation directory and add the following two lines to DartEditor.ini immediately before the existing ‑vmargs line:
-vm
/full/path/to/java
Important: On Windows, use double backslashes (\) as the directory separator:
-vm
c:\\bin\\java_jdk1.7.0\\bin\\javaw.exe
For example, DartEditor.ini might have:
-vm
/usr/local/buildtools/java/jdk-64/bin/java
-vmargs
You just need to download the Java Development SDK and your Java version should have the same bit width as your Dart Editor version. For example, if you're using a 64-bit Dart Editor, then you should use 64-bit Java. Otherwise, you might see a message like this when you try to launch Dart Editor:
You can download it here:
http://www.oracle.com/technetwork/java/javase/downloads/index.html?ssSourceSiteId=otnjp
and specify the java/bin directory in the darteditor.ini file.you can specify the Java SDK that Dart Editor uses. Go to your Dart installation directory and add the following two lines to DartEditor.ini immediately before the existing ‑vmargs line:
-vm
/full/path/to/java
Important: On Windows, use double backslashes () as the directory separator:
-vm
c:\\bin\\java_jdk1.7.0\\bin\\javaw.exe
For example, DartEditor.ini might have:
-vm
/usr/local/buildtools/java/jdk-64/bin/java
-vmargs
If it still doesn't work then you can follow this:
https://www.dartlang.org/tools/editor/troubleshoot.html
I made jre folder in my dart program folder.
And loaded there latest JRE. (Java runtime environment)
It stays in every new darteditor installation.
Better / right way would maybe be using path clause...
I dont know how to.. / dont want to use it.
My choise might need to load new version of jre now and then.
Hope this helps you...

java.exe always point to the path of JRE but not JDK

I have both jdk and jre installed on my windows 7.
I have set the JAVA_HOME to
C:\Program Files\Java\jdk1.6.0_23
I have add
C:\Program Files\Java\jdk1.6.0_23\bin
to PATH.
but the java.exe still pointing to my jre dir, which is
C:\Program Files\Java\jre6\bin
since when I run
java.exe -server
it complains
Error: no `server' JVM at `C:\Program Files\Java\jre6\bin\server\jvm.dll'.
can anyone tell me what else do I need to set?
since you are on windows, java doesn't work like that.
there is a java.exe in some windows directory (%windir% system32 for you)
This java.exe actually looks in the registry HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
PATH won't help ya! Since I tend to get lazy I delete the JRE and create a junction to the JDK instead.
Just remove java.exe from %windir%\system32
If you have a 64bit operating system, it will try to use the 64bit jre that is preinstalled on windows 7. You can try using add/remove programs to remove the 64bit jre. I've had this problem several times and I've always fixed it by removing the 64bit jre.
Right click MY Computer> properties > Advanced System Settings > Environment Variables >
Search for Path..
Remove the exisiting path and then add yours..
take care of the semi colon
make sure that your JRE/bin directory is not included in your path. the first instance of java.exe found while searching your path will be the one that is executed. if you've added your JDK to the path after the JRE then the JRE will always be picked.
you can also explicitly specify the full path to java.exe when invoking java. this will ensure that you always know what java jre/jdk you are invoking.

Can I specify the JDK path to compile against within an Ant build.xml?

I would like to use JDK 1.6 for a branch of a project while others keep using JDK 1.5. Developers want to occasionally switch between those.
So what is the best way to tell Ant's javac which JDK to use? By best, I mean a robust, transparent, low maintenance, versioned together with the source (Ant itself and JDK are certainly not, but they live at standard places).
The obvious -rather than best- way I guess would be outside of Ant: keep changing the JAVA_HOME env variable. However this would require developers to manually switch (another thing to remember: error prone), an changing all the -many- build servers (more work for me now).
Looking for some simple javac attribute e.g jdk-path, I noticed several instead (thanks to reading up on the net and in SO):
compiler- fair enough, but docs says "modern: .. javac1.5 and javac1.6 .. as aliases".. To me this suggests it won't make in any difference - will it?
source- seems only related to JLS version (althought not %100 clear from the docs linked above)
target - bytecode version
bootclasspath - some SO answers mention this, but pretty unclear and seems hackish
executable - path to javac, but not to libs.. -- seems the closest match, implicitly specifying JDK path? UPDATE: confirmed by JB Nizet
fork - it seems I'll need true here (otherwise it'll just ignore the above without error?). UPDATE: Any performance implications vs. default? (I guess JVM startup times are better these days, but still)
So, it seems none of these help in itself.. is any combination of these equivalent to setting JAVA_HOME prior to running Ant?
I have some hacks in mind (eg wrapping ant executable on each platform just to set that env var - quite sad), but I really hope I missed something :)
Using the executable attribute needs to set the fork attribute to true. This means that the javac ant task will launch an external process to execute javac.
When you launch javac manually, you don't have to specify any specific JDK lib directory: it knows where to find the libraries of the JDK it's part of. I'd say it will be the same if you launch it through ant's javac task (unless you override the bootclasspath).
Which version of the JDK is used to compile the classes should not necessarily matter. There may be differences in how a particular JDK compiles resources, but if the difference is just between v1.5 and v1.6, you can compile code to be compatible with Java 1.5 (or even 1.1) using a 1.6 JDK.
You can control what JVM version to compile for using the target attribute:
<javac srcdir="${src}"
destdir="${build}"
fork="true"
source="1.5"
target="1.6" />

How do you manage developing with multiple versions of Grails using Windows?

We've been using Grails for a little while now and have been through a few Grails versions now. We don't always want to migrate our 'older' apps immediately but often use a newer version for new development. Changing the Windows environment variables is inconvenient since I sometimes have to work on two related projects at the same time that are running different versions of Grails.
In Linux, I'd probably create wrapper scripts or aliases to allow me to specify on the command line a version switch but I don't believe Grails supports this.
How are others that need to code against multiple versions of Grails managing it?
Update:
I created a gv.bat file to set the GRAILS\_HOME and PATH environment variables. I added a GRAILS\_INSTALLS environment variable (c:\usr\local\grails on my box) and removed the %GRAILS_HOME%\bin reference from my PATH.
gv.bat
#echo off
SET GRAILS_HOME=%GRAILS_INSTALLS%\grails-%1
SET PATH=%GRAILS_HOME%\bin;%PATH%
To do any Grails work I run > gv 1.1.2 or whatever version I need to work with. I'd like to figure out how to do a string replace in the PATH to change the value but that turned out to be difficult for me
I have a couple of bat files which changes the GRAILS_HOME and the system PATH according to which version I'm using.
It's not the most beautifull solution at all, but at least works for me.
I have a batch file, that looks like below.
#ECHO OFF
if "%1"=="231" goto grails231
if "%1"=="232" goto grails232
if "%1"=="233" goto grails233
if "%1"=="234" goto grails234
goto end
:grails231
set GRAILS_HOME=F:\softwares\grails-2.3.1
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end
:grails232
set GRAILS_HOME=F:\softwares\grails-2.3.2
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end
:grails233
set GRAILS_HOME=F:\softwares\grails-2.3.3
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end
:grails234
set GRAILS_HOME=F:\softwares\grails-2.3.4
set PATH=%GRAILS_HOME%\bin;%PATH%
goto end
:end
It can be run like 'setgrails 233' and it will set the grails 2.3.3
IntelliJ allows you to specify which version of Grails to apply as a per-project facet configuration. The Eclipse plugin has yet to achieve this level of abstraction.
It's now MUCH much later, and GVM is not the tool it once was. Instead, I use SDKMAN (https://sdkman.io/) and, with Windows getting some linux-like tooling, or using Cygwin, etc. it's installable on Windows.
------ OLD answer below ------
GVM is a tool for unix/mac environments to manage Groovy/Gradle/Grails/more versions, and someone finally made a Windows equivalent called Posh-gvm (short for Power-shell GVM). It's very useful and easy to use to download and configure your environment for whichever version of these tools you want to use at any point in time.
If you're using an IDE, posh-gvm is still a great way to download/install the new versions as they come out, and your IDE can point into the posh-gvm install directories.
I have the same issue as you. For my concern, I have written a batch script (grails_version.bat) accessible from my Windows PATH home.
Set up your GRAILS_HOME to your standard Grails version and each time you want to run a Grails app into another version than the standard one, open a command prompt, run the batch script (>grails_version) and run your grails commands (ex: grails run-app).
If your are using IntelliJ, you can configure the grails version per application.
Here is the code:
#echo off
set v11=1.1
set v111=1.1.1
set v12M2=1.2-M2
set v12M3=1.2-M3
set v12M4=1.2-M4
set /p grails_version= What is the grails version (%v11%, %v111%, %v12M2%, %v12M3% (default), %v12M4%)?
if "%grails_version%" == "%v11%" goto :set_grails_home
if "%grails_version%" == "%v111%" goto :set_grails_home
if "%grails_version%" == "%v12M2%" goto :set_grails_home
if "%grails_version%" == "%v12M3%" goto :set_grails_home
if "%grails_version%" == "%v12M4%" goto :set_grails_home
if "%grails_version%" == "" goto :set_grails_home_default
:no_valid_input
echo The input version is not valid
exit
:set_grails_home_default
set grails_version=%v12M3%
:set_grails_home
set GRAILS_HOME=D:\Install\grails\grails-%grails_version%
path = %GRAILS_HOME%\bin;%PATH%
echo GRAILS_HOME=%GRAILS_HOME%
Enjoy.
I do that in Windows as below.
So I just change GRAILS_VER environment variable.
I can change my grails version anytime.
On Linux/Mac, GVM is a fantastic tool for installing and working with multiple versions of Grails, Groovy, etc. You can't use GVM itself on Windows1, but there is a clone posh-gvm that will run under Powershell on Windows.
AFAIK this is because Windows doesn't support symlinks
The thing I would change about these answers is the PATH handling. Each time you run the script and change versions, you will extend your path one more node. It works, but messy. Try creating a $path2 with no reference to your JAVA_HOME or GRAILS_HOME and the path become path2+grails+java. Example: set PATH="%PATH2%;F:\softwares\grails-2.3.1;path2java7.
The only reason I add the Java7 reference is that I need Java 6 for my older grails app and Java 7 for newer grails.
Check out this link, it explains exactly how to do that using cygwin and mapping several aliases.
Also, learn how the plugins directory work and replicate it several times for each version of Grails. I also use global plugins for the ones I use often, like tomcat, hibernate, dbUtil, console, etc.
Say you want to switch between 1.1 and 1.2M4 - you could have those directories setup with the plugins you are using:
c:\Users\username\.grails\1.2-M4\projects\projectname\plugins
c:\Users\username\.grails\1.1.1\projects\projectname\plugins
Then, take applications.groovy and make several copies, like
application.groovy.1.1
application.groovy.1.2M4
Now, to switch, you just need to rename the application.groovy.X to application.groovy and you are good to go (after running grails clean of course):
grails1.1 run-app
grails12M4 run-app
Lastly, there are other differences between versions (i.e. new 1.2 is introducing dependencies DSL), but most of the time things are backwards compatible enough that you can come up with a common denominator.
Some answers are outdated.
Seems that the best option nowadays is SDKMAN!:
SDKMAN! installs smoothly on Mac OSX, Linux, WLS, Cygwin, Solaris and FreeBSD. We also support Bash and ZSH shells.
Is also possible to install on Windows, but SDKMAN "can not be installed natively on Windows and requires WLS, Cygwin or MSYS+MinGW".
After that, you can choose the Grails SDK and which version you want. For example:
sdk install grails 1.3.7

Resources