SVN pre-commit hook for java code compilation - java

This sounds to me difficult but ensuring, if it is possible to add server or local svn pre-commit hook to prevent if there are any java code compilations. Usually when there is a requirement to merge bulk of java files from higher version to lower version, and if we do not have working local lower env setup, then this mechanism will help to save time setting up the local env.
Just thinking a solution - If I have a running QA AIX box of lower env, that I can utilize for code compilation while doing the checkins, in the hook I can add command as javac -classpath <AIX path>:$CLASSPATH:<corresponding jar> -d . filename.java, where filename.java will be passed as parameter. Along with connection credentials so that I can first connect to AIX before to compile. Is this approach possible, if yes how to add such conditions in hook. Or is there any thing already available that I am not aware of ?

Related

Ansible issue when trying to execute java command from playbook

I'm in the middle of automating some processes in a VM, we are currently using java 17 and have updated out jettys to jetty-11. Since in jetty-11 both home and base are separate it's important to initialize the jetty-base folder. I need to do it from ansible
I worked out a solution in local shell but trying that in ansible it's not working
- name: "Run initialization command"
shell: "nohup java -jar '{{ jetty_home }}'/start.jar jetty.base='{{ jetty_install_dir }}' --add-module=server,http,deploy,annotations,logging-jetty,jsp &"
There are no obvious errors when I run the playbook, just
TASK [jetty-distribution : initialize jetty-base] **************************************************************************************************************************
changed: [****************************] (cutting the vm name off)
Is there any solutions to this issue ? Thanks in advance
You most definately should be using 2 separate directories.
(repeated here for others that see this question in the future)
The jetty.home directory.
This is for the jetty distribution (or the more modern jetty-home tarball/zip).
The jetty.home directory is sacred, don't edit/change/remove/add/modify ANYTHING in this directory. You don't need to, for any possible configuration you can come up with (trust me).
The jetty.base directory.
This is the directory for your configuration, or instance of Jetty.
Make sure this directory does not nest inside/outside of the jetty.home directory, you'll just make your life needless complicated when it's time to upgrade (or even downgrade) your Jetty version.
Next, when it comes to initialization, turn off nuhup, that just hides any errors you might have during initialization. The --add-module command is terminal anyway and will do what it needs and then exit, it's not a daemon and keeps running. If you don't want to see the output, at least redirect it to an output file you can interrogate if there's issues.
Don't put it in the background either (the & at the end), the exit code will be useful to you if an error occurs.
aka
java -jar /path/to/jetty-home/start.jar \
jetty.home=/path/to/jetty-home \
jetty.base=/path/to/my-jetty-base \
--add-module=http,deploy,annotations,logging-jetty,jsp \
2>&1 > /path/to/my-jetty-base/jetty-init.log
Keep in mind that some modules, when added, require user interaction (to accept licenses). This can be handled in scripts by using the --approve-all-licenses option on start.jar.
Lastly, are you sure ansible supports the "Jakarta Big Bang" namespace changes that Jetty 11 implements?
See past answer on this: https://stackoverflow.com/a/66368511/775715
If ansible has updated to Jakarta EE 9, then go ahead and use Jetty 11, if they haven't, then stick with Jetty 10 (which is on Jakarta EE 8) until such time that ansible catches up with the rest of the world.

Jmeter linux shell cannot start server

Situation:
I have installed Jasper Reports Library (V6.5.1) on my local Linux server which generates PDF reports (Data is dumped in a temp Oracle DB table for the reporting engine).
It then serves this PDF back to the website from which I kick off the process.
Goal:
Install Jmeter to analyse performance / possible bottlenecks of "Jasper Reports Library" (aka Report Generation) on my local linux server (I cannot access this server via GUI, only shell).
I understand I have to connect my local Windows 10 machine (running same Jmeter 4.0) with this local server. On the server I have to start Jmeter 4.0 Server (via jmeter-server command) however I get an error and am stuck (have not found anything online or even people with the same goal unfortunately...)
Steps I have taken:
Download latest (4.0) bin from here
Extracted on local linux server in /opt/dlins/apache-jmeter-4.0bin
Trying to start server with /usr/lib/jvm/jdk1.8.0_102/bin/java jmeter-server (the default java version is 6 so through this I can run this app with java 8) - Instructions found here
-> Getting error: "Error: Could not find or load main class jmeter-server"
Any help regarding above or even any other tool you may use are appreciated (Maybe there is a preferable way to test performance for the above scenario)
There are 2 aspects related to your issue and screenshot:
1) Using java 8 instead of 6 - This can be done in several ways, depending on your needs and restrictions, such as the need to have Java 6 globally available for other applications and using 8 just to run JMeter, or just replacing 6 with 8 entirely. For the sake of brevity, I'll assume the first scenario, but there's documentation available for both and Dmitri T has partially explained it already.
Anyway, the same JMeter doc link you used, describes (just scroll down a few times) how to create a setenv.sh script in the bin directory and configure JAVA_HOME or JRE_HOME depending on your needs.
To set those variables permanently, you can place them in a file called setenv.sh in the bin directory. This file will be sourced when running JMeter by calling the jmeter script.
You seem to be wanting a JDK, so create the script and add inside JAVA_HOME=/usr/lib/jvm/jdk1.8.0_102, save and exit.
2) Running JMeter - To clarify a minor confusion, java MyCompiledClass instructs java to load and execute the "program" defined in MyCompiledClass, which is not what you want to do, because jmeter-server is a shell script. If you open it, you'll see that it calls the jmeter shell script which will do some configuration, end eventually call (in short) java -jar ApacheJMeter.jar with some arguments and options.
So, to run JMeter make sure your scripts are executable with chmod, and simply run from command line ./jmeter-server. From the same link:
Un*x script files; should work on most Linux/Unix systems:
jmeter - run JMeter (in GUI mode by default). Defines some JVM settings which may not work for all JVMs.
jmeter-server - start JMeter in server mode (calls jmeter script with appropriate parameters)
jmeter.sh - very basic JMeter script (You may need to adapt JVM options like memory settings).
mirror-server.sh - runs the JMeter Mirror Server in non-GUI mode
shutdown.sh - Run the Shutdown client to stop a non-GUI instance gracefully
stoptest.sh - Run the Shutdown client to stop a non-GUI instance abruptly
Amend your PATH environment variable so Java 8 bin would be before Java 6 bin like:
PATH=/usr/lib/jvm/jdk1.8.0_102/bin:$PATH && export PATH
Once done you should be able to just launch the jmeter-server script like
pushd /opt/dlins/apache-jmeter-4.0bin/bin && ./jmeter-server
More information:
Remote Testing
JMeter Distributed Testing Step-by-step
How to Get Started With JMeter: Part 1 - Installation & Test Plans

Scala - java.exe accessing internet?

Hm, so I set up Scala in order to start learning it.
When I compile a .scala script, though (i.e. "scala whatever.scala" in the terminal), java.exe is accessing the internet?
Why? Is that intended behaviour or did I forget to configure something?
The script I run was fairly simple, if that should matter:
args.forall(println)
It seems to me that Scala compilation happens inside a Java JVM. So when you compile Scala, the java command is executed.
Java JRE has a mecanism to update itself. When a new version is out, it asks the users (at least on windows?) if they want to install the new version.
It is possible that everytime a java command is launched, it checks for updates (?)
Edit: it is possible that this is because in some cases you are using a "compile server" for Scala. This means an extra JVM is spawned just for compilation and is kept alive after your initial compilation. Then next compilation will be faster because the compilation server will already have been started and all the classes will be loaded.
It is possible that a client JVM is communicating to the compilation server JVM by using a network protocol.
Check some links:
http://blog.jetbrains.com/scala/2012/12/28/a-new-way-to-compile/
https://github.com/typesafehub/zinc

Java - environment PATH variable doesn't include /usr/local/bin when using Process

In my Java application, I want to execute a python script with Process class. This python script needs to execute svn command. It seems that the PATH variable in my java application doesn't include /usr/local/bin. While I installed SVN 1.7.9 with homebrew and it's in /usr/local/bin. In the /usr/bin folder, there is another svn installed by xcode whose version is 1.6.x. This leads to a serious problem: when I execute the python script in my Java application, this script then executes svn in /usr/bin which is version 1.6.x. This version is too old to manage my working copy.
Is there any way to solve this problem?
Either set the PATH environment variable before you launch your (parent) Java application, or use ProcessBuilder. The latter allows you to control what the child processes environment will contain via the Map object returned by the ProcessBuilder.environment() method.
(But note that you typically can't change the contents of the child processes environment once it has been started ...)

Using Bumblee (Graphics Drivers) with Eclipse IDE [duplicate]

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 !

Categories

Resources