How to upload and execute a java program remotelly from IDE - java

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.

Related

Java remote interactions

I'm in internship, and my mission is to build a deployment program in Java. My approach was based on a "tasks to do for a deployment" model with dynamic instanciation (but this is not the point). Every task does something locally or on the remote server (sometimes both). For example, I have a Copy task which copies a local file to the remote server. Got some tasks like this for basic interactions (Move, Delete, ...).
The point is, each deployment module is a server which has different parameters (OS, connection params, ...) and basic programs. One of them is a Linux server, so I figured I could use SSH (with JSCh) to do the job. But the other is a Windows machine, with no SSH whatsoever. I searched everywhere for several days to find what could be used, with no results.
So here is my question:
what Java API should I use to get the job done?
Is it possible with Telnet or FTP?
Is it possible at all without ssh ?
Little detail: I don't have any control on remote servers, I can't install new protocols or programs, nor have a RMI server launched on them.
Thanks for your answers.
There are a few options to interact with a remote Windows server. If your local Java application is running on Windows (that is, both your source and target server are running Windows), you can spawn a new process and execute PowerShell commands - see this link for an example.
There are ways to copy and delete files on a remote server using PowerShell. Since you didn't fully specify your requirements, I don't know if that covers all your use cases or not.
If your application does not run on Windows, you'll have to resort to a pure Java solution like j-Interop to connect to the remote system using DCOM / WMI. See this page for a good introduction to WMI and j-Interop. Word of warning though - getting DCOM to work requires some configuration changes, specifically changing permissions on registry keys, on modern versions of Windows (Windows 7 and up).

Debugging between JRuby and Java

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!

Hosting of a Jar file

I have a jar file which contains two Java classes. Using the javamail API I have developed these classes to read and edit my mail, then send to another mail id.
I am able to execute this through my standalone system via Eclipse. Now I want to host this jar file somewhere remotely so that it would fetch the data in real time and execute the job regularly. I have contacted couple of hosting sites and they are saying that they require a war file instead.
Does anyone have any suggestions to this problem?
To give you another point of view and to be constructive, I would go with embedding your jar into a war application and you get some things for free, the most important I think is that you gain a managed application lifecycle so with a standard web application context listener you can start and stop your program in a managed way. Besides you have more hosting options and it is less work.
Good luck with that.
As I don't know of any services specifically for plain execution of executables, your best bet is probably getting a cheap VPS. With some searching you can probably find one that would work for around $5 USD/month. For a single simple app you'd only need around 128MB of memory.
Pick one up, install Java (whatever Linux distro you get probably has OpenJDK in the repositories), copy your files over, and set up a cron job to run the executable at a set interval.
For easier administration, install something like webmin and use that to configure the cron job. The command would likely just be java -jar /path/to/my/App.jar, and you can use the web interface to configure the intervals for the command to be executed.
For an app like this, I would avoid anything related to a war file. You aren't making an application with a web interface (like a PHP app or some such) so it really wouldn't be appropriate. You would have to write some extra code to make it compatible with a container like Tomcat, and on top of that the memory requirements for running the application server would be a lot higher.

Java Quickly web applicatoin deployment practices

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)

Common practice deploying/publish/debuggin a java webapp

I have always programmed my applications in php. But recenlty I discovered that best combination of language and server to achieve scalable comet functionality is Java + Jetty, because jetty support continuation, which eases the number of threads in the server. However, I'm slowly learning Java right now. I'm using Eclipse as my IDE with the plugin RSE(Remote System Explorer). When I used to program in PHP I just created a new php-file inside of htdocs in my Apache webserver, very simple to deploy. But now when I program in Java I have to compile the file too. Another flaw is that I cant create a Dynamic web project in RSE, so to deploy a webapp I have to drag all my file in my personal computer to my remote server and unzip and compile(manually via ssh). How do you guys deploy your java webapp in Eclipse?
And yes I haven't found any good answer to this on the web yet before asking this question.
Install a web server on your machine, and do all your development and tests locally on your machine. When the application is ready, deploy it on your remote server.
You don't have to compile it on the server. Java bytecode is portable across OSes and machines. You can build your war file on your machine and send it to the remote server.

Categories

Resources