Jython ignores jythonpath - classpath

My jython script is using Apache Tika, and it fails to load the Tika jar even though I placed it both in CLASSPATH and in PYTHONPATH. Here's what I'm doing:
> export JYTHONPATH=/full_path_to/tika-app-1.5.jar
> export CLASSPATH=/full_path_to/tika-app-1.5.jar
> java -Xmx512m -Xss1024k -jar /full_path_to/jython-standalone-2.7-b2.jar \
-c 'from org.apache.tika import *'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named apache
I'm using Jython 2.7 beta 2 on OSX. Java version is 1.8:
> java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
The same thing is happening on Amazon's EC2 Linux with Java 1.7.
When I'm using the non-standalone version of the jython jar (jython-2.7-b2.jar instead of jython-standalone-2.7-b2.jar), it seems to be working okay.
Any idea what's happening?

I think I found the problem. In Java, when using the -jar option, it more or less ignores the classpath. Just have to run the same code but with calling the jython 'main' class directly - not via '-jar'.

Related

kdb q - oracle access with babel fails

I have installed babel (interface between kdb and other dbs such as oracle) from here. After copying the oracle8 driver to the babel/lib folder I run the command from the babel documentation page
java -Xmx1024m -Doracle.jdbc.defaultRowPrefetch=10000
-cp "babel.jar:lib/ojdbc8.jar" de.skelton.babel.Babel 6868 oracle.jdbc.OracleDriver
which gives me
$ java -Xmx1024m -Doracle.jdbc.defaultRowPrefetch=10000 -cp "babel.jar:ojdbc8.jar" de.skelton.babel.Babel 6868 oracle.jdbc.OracleDriver
Error: Could not find or load main class de.skelton.babel.Babel
I tried to run the alternative
java -Xmx1024m -jar babel.jar 6868 oracle.jdbc.OracleDriver
which gives
Babel for kdb+ v1.34 2014.03.24
Error: could not load jdbc driver. Exiting.
I am running this on Windows 7 and have the following jre installed
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b31)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b31, mixed mode)
For windows, perhaps you need to use a semi-colon as separator in the classpath arg? e.g.
java -Xmx1024m -Doracle.jdbc.defaultRowPrefetch=10000 -cp "babel.jar;lib/ojdbc8.jar" de.skelton.babel.Babel 6868 oracle.jdbc.OracleDriver

How to configure buckminster to not use default JDK to compile during build?

I'm creating a build job on jenkins, the main part of it is a buckminster launch:
The job requires Java 1.8 and it's integrated JavaFX. The servers JAVA_HOME points to a Java 1.7 and all other jobs use that JDK.
So I configured a 1.8 JDK in the Jenkins system configuration and added it to the specific job:
Now when I run the job I get the following log (anonymised):
$ C:/Progra~1/Java/jdk1.8.0_40\bin\java.exe -Dbuckminster.output.root=PATH_TO_OUTPUT\buckminster.output -Dbuckminster.temp.root=PATH_TO_TEMP\buckminster.temp -Dworkspace=PATH_TO_WORKSPACE -Dqualifier=${QUALIFIER} -Xmx1024m -XX:MaxPermSize=128m -jar PATH_TO_BUCKMINSTER\buckminster4.4.0\buckminster\plugins\org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar -application org.eclipse.buckminster.cmdline.headless -data PATH_TO_WORKSPACE --loglevel info -S PATH_TO_COMMANDS\commands.txt
INFO: setpref 'targetPlatformPath=PATH_TO_TARGETPLATFORM/targetPlatform'
INFO: import 'PATH_TO_CQUERY/site.cquery'
INFO: Import complete.
INFO: build
Error: file PATH_TO_CLASS\TargetController.java, line 11: The import javafx cannot be resolved
... lot more of there errors
Warning: file PATH_TO_MANIFEST\META-INF\MANIFEST.MF, line 98: The JRE container on the classpath is not a perfect match to the 'JavaSE-1.8' execution environment
So this indicates that the "build" is not using the configured JDK 1.8 eventhough it is beeing started with "C:/Progra~1/Java/jdk1.8.0_40\bin\java.exe".
The question is how do I configure buckminster to use my 1.8 JDK?
can you try the answer i specified:
How to trigger Jenkins builds remotely and to pass parameters
I mean even JDK can be parameterised, let me know.

Playframework 2.3.6 reactive-stocks-java8 template issue in eclipse Luna

I have a problem using Eclipse as IDE for the reactive-stocks-java8 template coming with typesafe-activator-1.2.10
Here are my steps:
Install Eclipse Luna on my Mac.
Default JRE is 1.6, but I have the oracle JDK in /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/ after installing with the standard method. I add this JRE to the alternate JRE of eclipse
Install activator
I've downloaded typesafe-activator-1.2.10.zip, unzip it in a folder, add it to the path to have activator in the command line.
Create the project
$activator new
> reactive-stocks-java8
$cd reactive-stocks-java8/
$java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
$activator
[reactive-stocks-java8] $eclipse with-source=true
In eclipse
I import the project in the standard way (Import / Existing Project into Workspace)
in the java build path, The JRE is the 1.6. I change it to 1.8.0_25
I also have to change the java compiler
In my package explorer or the Problems view, no compilation error, great. Now I click on app/controller/Application.java to open it in the editor. In the editor, I've got some unresolved:
views.html.index cannot be resolved to a type
The type scala.collection.Seq cannot be resolved. It is indirectly referenced from required .class files
What am I missing?
here are the answers from the community
https://groups.google.com/forum/#!topic/play-framework/v6ep7DmfH18

Which version of Java does SBT use?

How to find out, which version of JDK SBT uses?
My laptop has both JDK 1.6 and JDK 1.7 installed, so I was just wondering.
You can use eval at the sbt prompt with the appropriate system properties:
> eval System.getProperty("java.version")
[info] ans: String = 1.7.0_45
> eval System.getProperty("java.home")
[info] ans: String = /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre
(The other answers are fine too, this is just another method.)
Just run sbt console and you'll get something like this:
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
Which shows you the version of Java being used.
Cheers
JC
It's actually easy.
Find the command line of SBT (cat `which sbt`) and see which Java it is.
For example, my SBT command line begins with:
/usr/bin/java -Xmx512M
And /usr/bin/java -version tells the Java version, in my case it is 1.7.
sbt -v is another way:
# sbt -v
[process_args] java_version = '1.7.0_121'
# Executing command line:
java
-Xms1024m
-Xmx1024m
-XX:ReservedCodeCacheSize=128m
-XX:MaxPermSize=256m
-jar
/usr/share/sbt-launcher-packaging/bin/sbt-launch.jar
[info] Loading project definition from /root/.sbt/0.13/staging/a6d8e5030b69785a9763/build/project
[info] Set current project to xx (in build file:/build/)
>
Here's a batch file method I created to get that info immediately from the command line (Windows only, but you can do something similar in a shell script):
#echo off
setlocal
sbt "eval System.getProperty(\"java.version\")" "eval System.getProperty(\"java.home\")"
#echo on

Setting up sbt to use Java 7 for compilation?

I'm getting compile errors when running the compile task as the sources reference new classes in java.nio.file package that only appeared in Java 7.
I have the following in build.sbt:
javaHome := Some(file("/opt/jdk/jdk1.7.0"))
fork := true
In sbt:
> show java-home
[info] Some(/opt/jdk/jdk1.7.0)
It compiles and runs fine in Eclipse. How can I set up sbt to use Java 7 for compilation?
The most reliable (perhaps only) way to do this at the moment it to start SBT with java in the JDK7 folder.
Modify your sbt launcher script; or use this one that allows you to specify Java Home (and so much more!) as command line options.
~/code/scratch/20111009 sbt -java-home /Library/Java/JavaVirtualMachines/openjdk-1.7-x86_64/Contents/Home
Starting sbt: invoke with -help for other options
[info] Loading global plugins from /Users/jason/.sbt/plugins
[info] Set current project to default-3e990a (in build file:/Users/jason/code/scratch/20111009/)
> console
[info] Compiling 1 Scala source to /Users/jason/code/scratch/20111009/target/scala-2.9.1/classes...
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.9.1.final (OpenJDK 64-Bit Server VM, Java 1.7.0-internal).
Type in expressions to have them evaluated.
Type :help for more information.
scala> java.util.Objects.equals(null, null)
res0: Boolean = true
Simply setting javaHome := Some(file("/Library/Java/JavaVirtualMachines/openjdk-1.7-x86_64/Contents/Home")) changes the Java version used to compile and fork processes, but does not change the version of the Java standard library on the classpath, nor the version used to run tests, which are always run the the same JVM as SBT.
If you use Linux or Mac, another possibility is to look at jenv, a command line Java manager.
It allows you to choose per project which JDK to use.
I use virtualenv, which is a tool from the Python ecosystem. In a nutshell, it is a shell script which allows you to change your PATH variable easily and get back to what it was before, if you need to.
First install virtualenvwrapper (a wrapper around virtualenv):
$ apt-get install virtualenvwrapper
Now create a virtual environment for, say, Java8 with Scala-2.11.
$ mkvirtualenv j8s11
Now, adjust ~/.virtualenvs/j8s11/bin/postactivate so that you define locations for all your tools. You can see an example below which works for me:
#!/bin/bash
JAVA_VERSION=1.8.0_31
SCALA_VERSION=2.11.5
SBT_VERSION=0.13.7
ANT_VERSION=1.9.4
M2_VERSION=3.2.5
GRADLE_VERSION=1.6
PLAY_VERSION=2.3.7
ACTIVATOR_VERSION=1.2.12
IDEA_VERSION=IC-135.475
PYCHARM_VERSION=community-3.4.1
TOOLS_HOME=/opt/developer
export JAVA_HOME=${TOOLS_HOME}/jdk${JAVA_VERSION}
export SCALA_HOME=${TOOLS_HOME}/scala-${SCALA_VERSION}
export SBT_HOME=${TOOLS_HOME}/sbt-${SBT_VERSION}
export ANT_HOME=${TOOLS_HOME}/apache-ant-${ANT_VERSION}
export M2_HOME=${TOOLS_HOME}/apache-maven-${M2_VERSION}
export GRADLE_HOME=${TOOLS_HOME}/gradle-${GRADLE_VERSION}
export PLAY_HOME=${TOOLS_HOME}/play-${PLAY_VERSION}
export ACTIVATOR_HOME=${TOOLS_HOME}/activator-${ACTIVATOR_VERSION}
export IDEA_HOME=${TOOLS_HOME}/idea-${IDEA_VERSION}
export PYCHARM_HOME=${TOOLS_HOME}/pycharm-${PYCHARM_VERSION}
PATH=${PYCHARM_HOME}/bin:$PATH
PATH=${IDEA_HOME}/bin:$PATH
PATH=${ACTIVATOR_HOME}:$PATH
PATH=${PLAY_HOME}:$PATH
PATH=${GRADLE_HOME}/bin:$PATH
PATH=${M2_HOME}/bin:$PATH
PATH=${ANT_HOME}/bin:$PATH
PATH=${SBT_HOME}/bin:$PATH
PATH=${SCALA_HOME}/bin:$PATH
PATH=${JAVA_HOME}/bin:$PATH
export PATH
Now you can just use workon to switch between environments. Example:
rgomes#terra:~$ workon j8s11
(j8s11)rgomes#terra:~$ java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
(j8s11)rgomes#terra:~$ scala -version
Scala code runner version 2.11.5 -- Copyright 2002-2013, LAMP/EPFL
(j8s11)rgomes#terra:~$ workon j7s10
(j7s10)rgomes#terra:~$ java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
(j7s10)rgomes#terra:~$ scala -version
Scala code runner version 2.10.4 -- Copyright 2002-2013, LAMP/EPFL
I'm assuming you want to change whatever you have set in JAVA_HOME by default, which you can do when invoking sbt:
JAVA_HOME=<path-to-jdk-home> sbt
This works for me on OSX with sbt 0.13.8
change javacOption to 1.7? I don't think setting the javaHome is necessary.