I have a large Java project that uses some Ruby scripts (primarily because of Ruby's support for "yield"). The Ruby code calls Java code which calls more Ruby code. It's very interleaved, but everything is driven from Java.
I'm using embedded jruby-standalone and building a jar-with-dependencies (via maven). I'm using a maven plugin to run jrubyc and generate .java files which maven compiles for me.
When I run the jar-with-dependencies, I can attach my debugger to the Java process with no problems, but I'd really love to be able to debug the Ruby code. Is there a solution for this?
I'm not launching any kind of jruby executable to which I could attach arguments. It's embedded in the jar and invoked via java -jar.
You could use the gem pry-remote.
Unlike pry, it does not require the process to be launched from a terminal (or a terminal emulator if you're on Windows).
It's not really a debugger per se, but if you add binding.remote_pry in your code where you wish to observe and react within that context (you could for example catch an exception), this would put pry in waiting mode for a remote connection, and from another terminal you should be able to connect to this process and debug it.
2 minutes hands-on tutorial is available here.
Drawbacks:
you cannot have 2 pry remote sessions.
your code must contain the right 'debugging' condition
I use this in pre-deployment environments when developing web apps with jruby, h2 and jetty server.
Good luck!
Related
Are there any easy way to run a java code from the IDE (Intellij for example) on a remote machine (without jar)?
I am trying to execute the code that I am developing in a remote machine, without package and upload a JAR every time that i compiled the code. The idea would be to run the code on a remote machine in a simple way and see the result in the IDE.
Summary:
The main idera is execute the program as a normal script in another machine and be trasparent to developer. Execution looks normal but the code are being executed on another machine.
This is an exploratory question because im not find any similar solution.
Without having a better idea of the big picture, I'd say that this may not be something that IDEs are likely to make easy for you.
There are possibilities:
Most IDEs support plugins and custom tool integration. You could set up automation to transfer the files and invoke them remotely. You'd basically be doing all the work.
You could use something like a remote disk mount or an editor with remote file editing support to store the files on the remote server and then modify them locally and run them remotely using a remote shell.
You could use some sort of cloud IDE setup that would allow you to edit the files that are hosted on the remote server and invoke them. Tools like this exist, although you'd have to install things and it might be more work than the other options here.
If the remote server is a web application server (e.g. Tomcat), you could certainly have your IDE deploy a WAR to the remote server and then invoke it over HTTP.
I'm exploring the use of Groovy as the default scripting language for my next project. Some basic requirements are:
load and run Groovy scripts, sending params in and getting results out, I know this can be done using GroovyShell or GroovyScriptEngine.
be able to run in debug mode stepping into the statements of the scripts (no need of managing breakpoints but execute statements in the code and take a look and the values of the variables in the current scope).
Yes, this is like a small IDE, but should be integrated into the app that manages running many scripts in parallel, and sending outputs of some scripts to inputs of other scripts (is a pipes and filters architecture http://www.enterpriseintegrationpatterns.com/patterns/messaging/PipesAndFilters.html).
I'm not sure if Groovy alone provides debugging and stepping into groovy code, or Java Platform Debugger Architecture should be used, or if this should be done by embedding an IDE into this system (it might be possible to embed Eclipse components).
These are my main concerns/doubts about the possibilities of using Groovy. any pointers are welcome.
Short answer is "No easy way to embed debugging functionality in an application that I am aware of". Please provide workaround instructions to use companion IDE or start deep research for any open source projects that have embedded script debugger functionality... and become great friends to the related contributing developers :-).
MORE INFORMATION:
Anything is possible when working with open source software. Yes, you can build a debugger that hooks execution of script (assuming you can keep process/threads separate) to step, create/halt at breakpoints, read variables currently in memory, etc.
Example: SmartBear ReadyAPI SoapUI NG PRO v4.6+(?) includes some base debugging embedded in their "Groovy Script" Test Step editor pane. (Disclaimer: SmartBear might have used other language or libraries to build their debugger features. I also am unsure if/when this feature will go to the SoapUI Open Source project - debugging is clearly noted as a PRO (paid) feature.)
Caveats:
Implementing debugger functionality is a MAJOR feature. You need debugger development experience (and/or even more time) to build functionality unrelated to your actual application. Make sure you truly need this embedded debugging before proceeding.
You should start with existing open-source groovy debugger to embed in your application... if one exists. SmartBear SoapUI NG PRO would be a start... but PRO feature is not open source.
I would like to write a program that sends an automated email based on a timer that runs constantly. I would then like to somehow export this program from eclipse to a computer that does not run the ide, and run it constantly in the background. I have figured out the code to send emails through java, my question is more regarding how to export this project as an application (or something) that can be run on any computer without running it through the eclipse IDE.
Any help, or directions to a better a resource to learn from, would be greatly appreciated.
The simple (manual) approach to turning a Java program into something that runs outside Eclipse:
Create a runnable JAR following the instructions here: http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-37.htm.
If your application depends on library methods that are not part of the Java SE library, pay particular attention to the "select library handling strategy" step.
Run the application from the command line as follows:
$ java -jar yourapp.jar arguments ....
Obviously, you need at least a Java JRE installation on the execution platform to run java, and you should have configured your system (the $PATH or %PATH% environment variable) so that typing java runs the correct thing.
If you are using a build system like Maven, Ant, Gradle and so on, you can automate the step that generates the JAR. (In fact, you can automate the entire build ... and break your dependency on any IDE.)
I DO NOT recommend trying to create an "executable" for your Java application. For a start, executables cannot be run on any computer. They can only be run on computers running a specific operating system / OS family. A second problem is that you are effectively embedding a JRE in your application. That makes applying the latest Java security patches difficult.
As for the problems of keeping the application running "constantly" and sending emails at specific times, that is just Java programming.
Use Timer & TimerTask - e.g. http://www.mkyong.com/java/how-to-run-a-task-periodically-in-java/
Use a job scheduler. For instance Quartz has an easy to use API for running jobs on a fixed schedule: http://quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-06
You need to create a runnable executable. You can do this by following these steps: http://www.wikihow.com/Create-an-Executable-File-from-Eclipse
Regarding the timer/scheduler, you may consider using Windows Task Scheduler (on Windows platform) or cron (*nix platform).
You will probably need to provide more information about the requirements you have for the timer in order to get a more specific answer there.
Currentyl i am working on a Java Web Application something simple JSF + Spring + Hibernate textbook application architecture, but i find my self losting time on uploading my WAR into production every time i have to do it and also in updating MySQL scripts, so
is there any good practice to deployed Java Web Application quickly?
Edit
This is the current Process:
I work on localhost where i quickly
deploy with eclipse
If everything work fines i export a WAR with eclipse
Upload this WAR through FTP into (hosted) production server
Move this into tomcat webapps
Thanks.
Tip. I'm Using eclipse as my IDE and ain't using Maven nor Ant
There are a lot of tools you can use to automate the build and deployment process:
Compile application => deploy to local server => execute unit- and integration tests => upload WAR file to web server if all local tests pass -- this is exactly the kind of functionality that Maven and Ant were invented for!
If you want to get rid of the tedious manual work involved in these tasks, perhaps checking them out once more is not such a bad idea.
Also, there are more advanced Continuous Integration solutions, like Hudson, which help you to better integrate source code management and deployment processes.
But none of those will speed up data delivery.
It seems like your most pressing concern is to find a provider to make your internet connection faster: However you manage your build process, uploading the content to the server will quite probably be the most time-consuming part.
The single most important thing is being able to script the stuff, so you can let the computer automate it.
You may be able to get Netbeans to create build scripts for your eclipse projects so you can just run ant to create your war. If not, keep doing it manually.
Then you need to script the ftp-session. That is easy - many scriptable programs exist (or you can just use a modern Norton Commander clone supporting ftp), so script it.
Then you need to script the MySQL-script changes. This is not easy to suggest, as you did not mention what needs to be done, but you can probably get very far with a Perl script or perhaps a small stand-alone PHP snippet expanding a macro.
THen you need to collect all the steps in a single script you can then easily invoke...
(or you could just figure out how to talk to the Tomcat administrative console which allows you to update WAR files remotely - but that may not be feasible or I would have expected you to do so already)
I have been searching for some time for a code coverage tool that will work with my client/sever application, but I have been unable to find a compatible tool.
My application stores images on a server, then displays them though a client which is launched via java webstart/jnlp file.
Any recommendations would be appreciated. I have already tried emma & clover, with no results. open source or commercials solutions are acceptable. thanks!
Instrument the classes with any of the code coverage tools you like (e.g. cobertura, which writes a local file cobertura.ser which can then be used for the report generation in a separate step).
Then, instead of running the signed or unsigned (which wouldn't work anyway) Applet directly in the browser, use the AppletViewer environment. The viewer runs the Applet in a privileged environment, without the Java Plugin Sandbox and thus the code coverage tool can do its work and write the report file.
Many of the code coverage tools use byte-code weaving and only write their results using a shutdown hook - when the VM shuts down. That is probably not working when used in a browser, since that's a special VM. Not sure, but maybe the Java Plugin starts a separate VM for Applets which is never being shut down.