Scala Play Framework on Windows NoClassDefFoundError out of the box - scala

I am trying to run the starter scala Play Framework code on my windows machine. I run:
git clone https://github.com/playframework/play-scala-starter-example
import it into IntelliJ, and type sbt run on the command line. It runs the server on port 9000, but when I try to access the page, it fails with a bunch of java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter. So it fails right out of the box. I don't know if it has to do with me using Windows. Any ideas?

This is because you're using Java 9
You need to add --add-modules=java.xml.bind option to your JVM. For example in Windows you need to go to the folder your project resides at
.\sbt-dist\bin
and change set _JAVA_OPTS=%JAVA_OPTS% to set _JAVA_OPTS=%JAVA_OPTS% --add-modules=java.xml.bind in sbt.bat

Related

Running an Erlang Application in Eclipse is throwing an exception

I have installed Erlang OTP 25.0, erlide 0.56.0, Eclipse 2022-09 & Java 18. I have created a new Erlang project and module. I am facing 2 issues.
Issue #1:
Getting an error when I tried to launch the Eclipse after creating the Erlang project.
Issue #2:
When I tried to run the application, I am getting an exception "Launching App1 has encountered a problem. An internal error occurred during launching App1. Expected the service OtpNodeProxy 5756dc#null FAILED to be running, but the service has FAILED" as shown in the screenshot ErlangRunConfigException. Please help me in resolving the issue.
I have followed the procedure given below.
Installed Eclipse and Erlide plugin
Installed Erlang OTP 25.0 from https://www.erlang.org/patches/otp-25.0
Updated the environment PATH to refer to the Erlang installation path. I cross-checked this setting by typing "werl".
In Eclipse, Erlang InstalledRuntimes is automatically updated with the Erlang version 25.0. Refer to the screenshot ErlangInstalledRuntime
Created a Erlang project and module.
Edited the Hello.erl with HelloWorld code.
In Eclipse->RunConfguration, created an ErlangApplication (refer to the screenshot RunConfig-ErlangApp-Erlang). I set RunTime and Node name as shown in the screenshot RunConfig-ErlangApp-Runtime. Selected the Windows PATH as shown in the screenshot RunConfig-ErlangApp-Environment.
Hello.erl
```
-module(hello).
-export([hello_world/0]).
hello_world() -> io:fwrite("hello, world\n").
```
Images:
ErlangRunConfigException.png
ErlangInstalledRuntime.png
RunConfig-ErlangApp-Environment.png
RunConfig-ErlangApp-Runtime.png
werl output
RunConfig-ErlangApp-Erlang.png
Project structure
Eclipse Launching Error
Unfortunately, Erlang 25 doesn't load beam files older than v21, and the files included in erlide are that old. I am not really maintaining the project anymore, I can try to rebuild with v25, but can make no promises. Even then, the debugger will no longer work, it can be good to note.
The reported issue is seen with the latest Erlang version 25.0 and the older versions I have checked till 23.0. As a workaround, I have migrated to IntelliJ IDE.

Why does Jenkins change my workspace path?

i have installed Jenkins on Windows 10 and each time i try to execute a maven project or just try to execute mvn clean test (command line), Jenkins decides that my new workspace should be: C:\Windows\system32\config\systemprofile\eclipse-workspace\ while my project is in C:\Users\username\eclipse-workspace.
Jenkins starts in the directory C:\Windows\system32\config\systemprofile\AppData\Local\Jenkins.jenkins\workspace\projectName and even if i run a cd command i will have this problem:
The driver executable must exist:
C:\Windows\system32\config\systemprofile\eclipse-workspace\projectname\drivers\chromedriver\chromedriver.exe
My chrome driver is not there obviously but it's in C:\Users\userName\eclipse-workspace\projectName\drivers\chromedriver.
It looks like than Jenkins changes my user.home.
I went to config file and set:
<workspaceDir>C:\Users\userName\eclipse-workspace</workspaceDir>
but it's still looking for the driver in C:\Windows\system32\config\systemprofile\eclipse-workspace\projectname\drivers\chromedriver\chromedriver.exe
This part: C:\Windows\system32\config\systemprofile\ is obtained using in Java System.getProperty("user.home"). Running it with Jenkins seems to modify it.
Why is it looking for my driver there?
Why can't it just stick to my workspace folder?
How can i solve this?
Thank you
I think i solved it. I was running under Local System Account
https://jenkins-le-guide-complet.github.io/html/sect-windows-service.html#fig-hudson-windows-service-config
I had edit the service as shown in the link.

Running a Tika server from eclipse to be accessed from hosts other than localhost

I have the following question: I have imported in eclipse the tika-server subdirectory of the tika-trunk main repository and managed to import it to eclipse and I am able to start the "Apache Tika 1.7-SNAPSHOT server" on the machine I run eclipse (localhost). My problem is that I can only access Tika from this machine (localhost).
I know how to solve this problem when I start the Tika server from my command line (see post Stopping a Tika server properly ), but I do not know how I can pass "-host 0.0.0.0" in order to instruct eclipse to do the same. I know that this might be solved through the "Run Configurations" eclipse menu but it is not intuitive to me how I can accomplish that. Thank you in advance !
First up, you need to open the Tika Server Cli class in eclipse. Then, do Run As followed by Run Configuration, as shown here:
Now, in the configuration for the Tika Server CLI, in the program arguments box, enter the arguments you want to give to Tika, eg --port 9876 as shown here
Finally, hit Run and the Tika Server will start with the alternate port you've givne
I think the only solution so far I found is to edit "TikaServerCli.java" and switch "public static final String DEFAULT_HOST" from "localhost" to "0.0.0.0". Then you can start the server in a way that can be accessed by everyone and not only by localhost.

How to run build using graphics drivers by using optirun (Bumblebee) from IDE (Netbeans, Eclipse)?

Does anyone know how to make eclipse or netbeans use the graphics card in optimus laptops by invoking optirun (bumblebee) inside the IDE so that one can just use the run button in the IDE to run the program in a graphics card within the IDE.
In simplest form I just want the IDE to do the equivalent of optirun ./javaproject
The way I did this in Eclipse was to first start the Java debugger jdwp and listen to a port. Then start the JVM with optirun java ... and use jdwp to connect to this port. Both tasks can be started at the same time in Eclipse by creating a Launch Group in the debug configuration settings (Run -> Debug Configurations). In detail:
Create a Remote Java Application debug configuration with "Standard (Socket Listen)" Connection Type and some arbitrary port, e.g. 56789. This attaches the Java debugger jdwp on port 56789 to a virtual machine which accepts debug connections at this port.
Now we need to start a JVM with optirun. This can be done with a External Tool Configuration (Run -> External Tools -> External Tool Configurations). Create a new Program configuration in the left side of the External Tools Configurations window. You could directly start optirun java <additional arguments> by filling in the required fields. However, I have decided to use a shell script which is reusable by different projects (As can be seen below, there is one part missing to make it entirely reusable. I'm glad for any help from more experienced Eclipse users...). Hence, the Location field points to this shell script. The script itself accepts three arguments: the classpath for the project, the name of the Java executable, and the port number. These arguments can be passed to the script in the Arguments field of the Main tab, e.g.
${project_classpath:${selected_resource_name}}
ExecName
56789
The shell script looks like this, assuming optirun is in your PATH:
#!/bin/sh
CLASS_PATH=${1}
JAVA_EXECUTABLE=${2}
PORT=${3}
# TODO: fix this java library path: pass it as an argument as well. Is there an Eclipse variable which stores this?
JAVA_LIBRARY_PATH=/usr/local/share/OpenCV/java
#------------------------------------------------------------------------------
optirun ${JAVA_BIN} -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:${PORT} -Djava.library.path=${JAVA_LIBRARY_PATH} -Dfile.encoding=UTF-8 -classpath ${CLASS_PATH} ${JAVA_EXECUTABLE}
#------------------------------------------------------------------------------
Finally, the two pieces are brought together in a Launch Group in the Debug Configurations window (Run -> Debug Configurations). Create a new Launch Group and add the two previously generated Debug configurations by clicking on Add in the Launches tab and by selecting the appropriate configurations.
Note that due to the classpath variable in step 2 (i.e. ${project_classpath:${selected_resource_name}}), the appropriate package needs to be selected in the Package Explorer before clicking on the run debug configuration button (make sure that the Launch Group is selected).
This solution works perfectly for me: I can debug Java code inside Eclipse which calls native code involving CUDA optimizations and Bumblebee only activates the discrete graphics card when necessary.
Just use optirun to start the IDE. For example, optirun eclipse or optirun netbeans
I build the project in Netbeans (F11) and run the following in a terminal:
optirun java -jar path/to/javaproject/dist/javaproject.jar
Mind that if you have any java parameters in your project, you need to add it manually. My workflow is like this:
Locate the Java options from the project, open Project -> Properties, Run. At VM Options I see -Djava.library.path=lwjgl/native/windows;:lwjgl/native/linux. I also have some parameters that I want to pass to main(String[]). With this information, I open a terminal and run:
cd path/to/javaproject
optirun java -Djava.library.path=lwjgl/native/windows;:lwjgl/native/linux \
-jar dist/javaproject.jar some paremeters
Another hint, if you have to open and close the program frequently, run optirun bash in a different tab so that preparing the use of the graphics card becomes faster. Alternatively, you can run optirun netbeans, but that means that the nvidia card will always be on even if you are programming which increases power use and increase the heat.
Important: if you are using a 32-bit JVM or Java libraries on a 64-bit machine, you also need to install the 32-bit drivers and libraries. For Ubuntu, the nvidia package already contains 32-bit drivers, see this answer. For other distros, you likely need to install lib32-* packages for Mesa, VirtualGL and nvidia-utils.
You can also rename java to java_real and use this portion of code as your java command :
#!/bin/bash
path=$(dirname $(readlink -f $0))
args=""
runner="$path/java_real"
for var in "$#"
do
if [ "$var" = "-3d" ]; then
runner="primusrun $runner"
else
args="$args $var"
fi
done
$runner $args
NOTE : I had to do this in /usr/lib/jvm/java-7-openjdk-amd64/jre/bin, not in /usr/bin to make it work with Eclipse.
In Eclipse, just add "-3d" in your program arguments and you're good to go !

deploying a scala app built using IDEA

I developed a simple scala app that uses casbah to query the DB for the command line argument passed to it. For example
$ querydb.scala execution 10
it will run a casbah query to find 10 records matching execution in mongo. Now i have two questions.
1) How do i test this in my local. If i click execute in intellij it is just running the program, i am not able to pass command line arguments to my program.
2) How do i deploy it to run on my server, it is just going to used as console app in my ubuntu server, but im not sure how i should deploy this, which files i should put up on the server and how do i execute it in server, and stuff like that.
Any pointers would be useful for me.
or try to use sbt, IDEA has a plugin with sbt, the wiki of it has an explanation on how to use it.
I usually use sbt directly in Terminal instead of running in IDE.
1) First you need to find "Select Run/Debug Configuration" button at the top of your screen
Click on it and choose edit
Create new one, if you haven't got it yet.
Your program parameters should be written in "Program parameters" field
2) Compile your .scala files with scalac and you'll got .class files.
Then deploy it, as you usually do with java code. Hence you don't need to install scala on target machine - all you need is JDK.