I'm struggling trying to get remote actors setup in Scala. I'm running Scala 2.10.2 and Akka 2.2.1.
I compile using [I've shortened the paths on the classpath arg for clarity sake]:
$ scalac -classpath "akka-2.2.1/lib:akka-2.2.1/lib/scala-library.jar:akka-2.2.1/lib/akka:akka-2.2.1/lib/akka/scala-reflect-2.10.1.jar:akka-2.2.1/lib/akka/config-1.0.2.jar:akka-2.2.1/lib/akka/akka-remote_2.10-2.2.1.jar:akka-2.2.1/lib/akka/akka-kernel_2.10-2.2.1.jar:akka-2.2.1/lib/akka/akka-actor_2.10-2.2.1.jar:." [file.scala]
I've continuously added new libraries trying to debug this - I'm pretty sure all I really need to include is akka-remote, but the others shouldn't hurt.
No issues compiling.
I attempt to run like this:
$ scala -classpath "[same as above]" [application]
And I receive a NSM exception:
java.lang.NoSuchMethodException: akka.remote.RemoteActorRefProvider.<init>(java.lang.String, akka.actor.ActorSystem$Settings, akka.event.EventStream, akka.actor.Scheduler, akka.actor.DynamicAccess)
at java.lang.Class.getConstructor0(Class.java:2810)
at java.lang.Class.getDeclaredConstructor(Class.java:2053)
...
Looking into the source code, it appears that Akka 2.2.X's flavor of this constructor takes 4 arguments (the Scheduler is removed). But in Akka < 2.2.X, the constructor takes 5 args.
Thus, I'm thinking my classpath isn't setup quite right. At compile-time, Scala must be finding the <2.2.X flavor. I don't even know where it would be finding it, since I only have Akka 2.2.1 installed.
Any suggestions!? Thanks! (Please don't say to use SBT).
The problem here is that the Scala distribution contains akka-actor 2.1.0 and helpfully puts that in the boot class path for you. We very strongly recommend using a dependency manager like sbt or maven when building anything which goes beyond the most trivial projects.
As noted in another answer, the problem is that scala puts a different version of Akka into the bootclasspath.
To more directly answer your question (as you said you don't want to use sbt): you can execute your program with java instead of scala. You just have to put the appropriate Scala jars into the classpath.
Here is a spark-dev message about the problem. The important part is: "the workaround is to use java to launch the application instead of scala. All you need to do is to include the right Scala jars (scala-library and scala-compiler) in the classpath."
Related
I would like to use jython for basic web scraping task rather than learning java. To learn the basics I'm using an example from http://blog.databigbang.com/web-scraping-ajax-and-javascript-sites/ I've been unsuccessfully trying to run the gartner.py code from Windows cmd. Could anyone suggest a resolution to why both
jython -J-classpath "path\to\the\jars\*" path\to\gartner.py
and
jython path\to\gartner.py
keep on throwing out
Traceback (most recent call last):
File "path\to\gartner.py", line 1, in <module>
import com.gargoylesoftware.htmlunit.WebClient as WebClient
ImportError: No module named gargoylesoftware
given I've got environment variables set up for jython path\to\jython\bin, for java path\to\Java\jdk-14.0.1\bin and for the htmlunit-2.40.0 I've added path\to\jars\htmlunit-2.40.0\lib to the CLASSPATH.
I understand that jython should pick up the specified package in jython -J-classpath "path\to\the\jars\*" path\to\gartner.py but it does not find it. Also, I understand that in the case of jython path\to\gartner.py the defined CLASSPATH variable is available to Java pointing at htmlunit-2.40.0 (as mentioned above) whilst jython serves only as a translator from python to java. So - in my understanding - java shouild have all parameters available to import the desired module. Please, could anyone confirm?
I appreciate this subject has been somewhat discussed but there is no clear resolution available. What could I be missing?
The error looks very clearly like you're missing a Java dependency. The jython issue with this specific library has already been discussed in a different thread: instantiating a webclient object in jython giving strange results
There is a bug in JFX which often manifests when calculating screen co-ordinates
https://bugs.openjdk.java.net/browse/JDK-8194727 and
https://bugs.openjdk.java.net/browse/JDK-8190400
I've tracked the problem down to the implementation of GeneralTransform3D, which is part of the javajfx runtime.
I've submitted a bug report to Oracle, but until it is accepted, fixed, and makes it to a release, I need a way of fixing my application.
In java 8 i was able to create a jar containing a fixed version of the class and install it in the lib/ext folder. This seemed to work and the JFX implementation used my impl over its own.
In java 10 the extension mechanism has been removed. Adding the patch jar to the classpath doesn't work as it is too late in the classloading process.
Is there a way to override/patch an implementation of the core java classes in Java 10?
Note that i'm not using this class directly, it is used by the framework
Once again, Alan gives the best answer as a comment. :) Quote:
--patch-module javafx.runtime=patch.jar is the right way to override classes in this module
If you need to "override" a class in a platform module, use --patch-module to do that. If that drags in additional dependencies, make sure to make them readable with --add-reads.
I needed to do this but I was launching Java from C through the JNI interface (instead of the command line). Just transposing the command line args to JavaVMOptions didn't work. Instead it all goes in one arg as follows:
JavaVMOption options[N_ARGS] = { 0 };
options[0].optionString = "--patch-module=javafx.runtime=patch.jar";
It took a lot of digging to figure this out, so hope it saves someone else some time.
Looks like a solution is possible using java agents, as per this question
Replace a class within the Java class library with a custom version
I have a java class that I want to call on post deployment of modules for MarkLogic in both ml-gradle and roxy. Are there any examples for either of these out there?
For ml-gradle, is it fine to have the Java class called at the end of "mlDeploy"? If so, you can do that easily by creating a Gradle task of type JavaExec, and then having mlPostDeploy depend on it, e.g.
mlPostDeploy.dependsOn myCustomTask
If you need it to run immediately after modules are loaded and before any other ml-gradle commands are executed, you'll need to make your own command that's part of mlDeploy - see https://github.com/marklogic-community/ml-gradle/wiki/Writing-your-own-command for more info and feel free to post an issue in ml-gradle if you run into problems.
Roxy runs on Ruby, so you will have to do a system-call to invoke Java. We do that internally too to invoke MLCP, Corb2, XQSync, and RecordLoader:
https://github.com/marklogic-community/roxy/blob/master/deploy/lib/server_config.rb#L1399
HTH!
I'm new to java development, I just want to use javac for my build system. I'm using java to add a feature to a program someone else wrote, specifically involving GeoTiff images.
I found a class online that I would like to use, however I'm having trouble building the class, no matter what I do I get this message:
javac GeoTiffIIOMetadataAdapter.java
GeoTiffIIOMetadataAdapter.java:11: package com.sun.media.imageio.plugins.tiff does not exist
import com.sun.media.imageio.plugins.tiff.GeoTIFFTagSet;
I'm on RHEL5, so I installed the package I thought I needed, jai-imageio-core.x86_64. But the problem persists. I think that I'm not setting some variable corrently (like -sourcepath or something). I would appreciate any help.
You need to include the jar with -cp or -classpath.
So your compile would be like java -cp "<location to jai_imageio-1.1.jar>" <your java class> .
I think you need this jar file.
You can read more about javac here.
Find out where the package installed the jar file with the class you want to import, and add it to the javac commandline in the -classpath. (You then also need to include it in the classpath when your plugin runs; how to do that may depend on the program it plugs into).
I think that I'm not setting some variable correctly (like -sourcepath or something)
This tutorial briefly introduces the usage of environment variables in Java: PATH and CLASSPATH
This one seems to be the most popular answer to various classpath related questions I've seen at online forums: Setting the class path.
To avoid "blind recommendation" I quickly skimmed through it before adding to this answer and, well... it really covers most of what one needs to know to deal with classpath. Pretty good; the reason why I didn't look into it before is that there always has been some guru nearby who explained stuff to me.
I have a java program that I'm required to compile into a Linux native program using gcj-4.3. This program requires serial port access. The javax.comm api provides serial port access but I'm not sure how to get my compiled java program to use it.
The target box has Java installed, but of course my compiled program isn't running in the JRE...so I'm not exactly sure how I can link in the comm.jar file or how that file can find the .properties file it requires.
I wonder if I can just compile the comm.jar allong with my .jar file and link the two object files together. Can my code then reference the classes in comm.jar?
Thanks in advance for your help!
I'm not an GCJ expert but I have some suggestions (I'm not providing the syntax, this will require some exploration that I didn't perform):
first, I think that you'll have to compile comm.jar into a (shared) library,
then, you'll have to link your code against the library,
finally, use the GCJ_PROPERTIES environment variable to pass properties to the program at invocation time.
The following pointers might be helpful to implement this:
GCJ---The GNU Compiler for Java (great resources IMO, covers all the steps mentioned above)
GCJ – Getting Started (more an intro but still nice)
Compile ActiveMQ with GCJ (more use cases but I don't think they apply here)
And of course, the official documentation :)