Compiling and Executing Java Remotely - java

If you do not have Java installed in your computer, is it possible to compile and execute Java programs by pointing to a PC which has?

If you have Java installed on your machine then zip that whole directory and give that to those guys. They can extract it to their machine, they don;t need admin rights for that. Thats it you are done and can use javac and java to compile and run. You can add the bin directory to your PATH then you can executes these command from anywhere.
Also you can login to a remote machine where JDK is installed and the logged in user have execute permission.

Dude, you have an organizational problem, not a java problem. If the higer-ups don't want programmers hacking on the regular boxes, then you really shouldn't be trying to bypass the protection. Way to get in serious trouble.
Do it the right way - speak to someone with the authority to get the jdk & eclipse (or netbeans, if you insist) installed.
As a last resort - anyone who wants to learn java will have a home PC or a laptop. Just remember, if you have to use your home PC to learn java, then you owe your employer nothing by way of loyalty or obligation to use your new skills working for them.

If they are able to log in to a PC which has the JDK and JRE installed, then they should be able to compile and run their Java programs from that PC. It shouldn't make a difference whether they're logging in remotely or locally. Java can be run remotely in much the same way that any other program can be run remotely - although exactly what that way is probably depends on what method of remote login is used (SSH, remote desktop, etc.).

Theoretically, they could use a remote desktop solution like VNC to compile and run their programs on a different computer, but it's going to be sluggish and uncomfortable to use, probably giving them a bad impression of Java. Besides, if your company's IT policies are as paranoid as it sounds, you'll most likely never get the permission to run a VNC server.
It would be much better to lobby management to have a JDK installed on these people's PCs. Stress the value of their emplyoees acquiring new skills.
If the company is dysfunctional enough that this is not permitted, seriously consider getting a job somewhere else.

yes, check out Java6's The Java Compiler API. It allows you to compile code given in string and has nice error support.

This will be very painful for them to use going forward. Couldn't you get the JDK installed?
As described in another answer, you should be able to copy a pre-installed JDK to the local drive, just setup a batch file to setup a JAVA_HOME and add to path.
You can also copy Eclipse locally - you don't need to install it.

Related

What is the preferred way to deploy a jar to people who don't have java?

I have a program which is being distributed to companies where java is either not allowed on their computers or not allowed to be updated for various security reasons. It is a java jar as it stands, a simple survey-type desktop program using swing.
My question is, how can I distribute this program to the various end users when they aren't allowed to install anything on their systems, including java? They will be running the program from a flash drive, so it has to just run from there with no installation or copying to the disk or anything like that, and no guarantee that java will be installed.
All of the target users are on windows, at least, so an exe is an option.
EDIT: Based on what Rob has said, does anyone know if distributing a private JRE is possible? Bundling a JRE which is preinstalled on the flash drive, and then pointing the jar to that?
I don't believe that there is anyway to do this using Java. The role of the JVM is to interpret the java byte code into instructions which will function on the device which the JVM is installed on. If no JVM is installed, your intermediate code (JAR file) can't be run.
You may look into distributing your app via ClickOnce if .Net development is an option. It will allow Windows users to install and run applications with limited permissions even without administrative access on their computers.

Integrating Java compiler in my application

I want to integrate java compiler in my application but I don't have any idea how will I do that.
I want that user could compile and run code on my application.
If anyone can help me then please tell me from where I should start.
Starting Java 1.6, the standard JDK ships with an API to the compiler. Meaning, you can easily write a Java program that will compile other programs.
http://docs.oracle.com/javase/7/docs/api/javax/tools/JavaCompiler.html
EDIT as per Aaron's comment: an application using the compiler API must be run using the full JDK. The JRE doesn't include the compiler API implementation.
A second alternative is to embed the Eclipse Java compiler into your code. The advantage of this is that your application doesn't need a SDK to run - just add this single JAR.
Details are documented here: http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-using_batch_compiler.htm
Note: Adding a compiler to an application creates an enormous security risk. It basically means anyone can start doing anything with your application. Things that spring to mind are:
Attacking other computers, people and sites
Looking at all the data on the computer on which the application is running
Analyzing the network the computer is in and attacking any other computer in the same network
Installing Trojans or viruses on the computer

how to make program able to install

I have finished developing my java application using netbeans. Now I want to give it to others. How can I change it so that user can directly install and run my application without having to run it from IDE or command line.
Thank you
You have a few options:
If "install" means an icon to click on and run your app, you can create an installer to do so. You don't specify your target operating system. I'd recommend Googling for installers like Wise.
You can create an executable JAR with a launch command file for users to execute.
You can use Java Web Start.
You'll have to assume that your user base has a JVM of the correct version installed and available for your app to use.
You don't say anything about databases or other services, so I'll assume that you have a main method that you want to launch.
For a simple application with no dependencies, the easy way is to create an executable JAR file.
For a complicated application, you need to package up the primary JAR and the other things that it depends on, and present that in a way that the user can install. This might be a simple ZIP file (or equivalent) for the user to unzip. (That is the way that Eclipse and is distributed for example). Alternatively, it might be a fancy installer ... which you would need to write or generate. (There are a variety of installer generators out there: some free / open source, others commercial.)
Basically, you need to balance "ease of installation" for the user against the amount of effort (and money) you are prepared to spend on creating installer infrastructure for your application.
Alternatively, if you are prepared for the application to be hosted on and launched from a web server, then Java WebStart is a good alternative to an installer, not least because it removes the need to get the user to reinstall to pick up newer versions of your application.
Look into some free packaging installer like presented in here.
You should understand how your application should be setup on a "clean" machine and describe it to the tool you use.
I've used IZPack in the past and am very pleased with it.You will also need to know how to package your app into jars/wars/ears (or other).
I hope this gives you a staring point.
You can give JSmooth a try and see how it works for you. I haven't used it before but a co-worker of mine has several times and he seemed to be happy with it.

Create an installer in Java

I want to create an installer using Java that install at first MySQL. The user tape at first the password of root user. Then the installer copy jar file into program files and create shortcut on desktop.
So my question how to install MySQL automatic via Java. Is there any way??
Thanks in advance.
best regards,
Ali
Depends on the platforms you want to install onto. Basically if you know how to do it via the command line, then you can write a shell script that is executed from Java, or a series of command line statements that are executed from Java to do it.
Since you mention root user, I'm guessing some flavor of linux? Doesn't MySQL already have ways of doing this that come with the installers and/or binary distributions?
This write-up might help you in creating a java installer: Convert Java to EXE (also has information about other platforms)
But, before going for that, I would like to ask you, why do you want o bundle MySQL with your java app? The recommended way, if you want a DBMS bundled in your app can be:
Ask the user the install MySQL him self. You app will use it.
Use SqLite (embedded RDBMS). Or even simpler, Berkley DB for a Key-value store. This approach will be super light and no installation needed.
You can try to perform a 'private' ad-hoc MySQL installation that is only used by your application: that means you will have to copy the binaries (please note they are different for each platform) plus some custom configuration files to a 'mysql' subdirectory of your programs' main directory.
I can assure you it won't be easy and fast to do. You have to struggle a bit making it work under each platform. This kind of stuff is always a bit tricky.
If you prefer to install MySQL in a system-wide manner (as a service, using the provided install package) you'll have to embed the package into your setup program and then use the proper operating system commands to install it. That would be different on each platform, and under Linux you'll have to install the proper package for each distro. Messy.
You can look at some commercial solutions for making Java install programs. See install4j for example.
Shipping MySQL with your Java application is not so easy. Are you sure you need MySQL, and you cannot use some simpler alternatives, like sqlite? If you choose sqlite, there are some 100% java solutions, and that means no difference between platforms and easy deploy of your application.
Think about it, listening to this simple advice can make you save 14-15 hours of work and debugging (with always some possibility of failure, because complex installers do fail).

Java LoadLibrary UnsatisfiedLinkError, though Java can see the file and runs on another computer

This problem is really befuddling me and hopefully someone could help me out. I've written some plugin libraries for a large java software. Everything works fine and well on my development computer. However, after I compiled and wrapped the software in Nullsoft Installer and install onto another computer, everything but the native dll plugins I developed runs, and I get a UnsatisfiedLinkError when I call System.loadLibrary. The installer works on my dev computer, the installed software runs fine even after I moved the original software. Here's what I do know:
the native libraries are deved in .NET (C++/CLI) hooked in by JNI
The software on the new computer is loading the right library path, can see the native dlls. In Java, I've added a segment to check the permissions on the files using File class, Java runs fine on library_dll.canRead() and library_dll.canWrite(), but hangs/crashes on library_dll.canExecute().
If anyone can help me, I would really appreciated it!!! Thank you all!
Does the target computer have .NET installed, and the right version of .NET at that?
I can't say I've ever done any .NET/JNI interop - it sounds potentially tricky to me. Have you looked at using JNBridge to make things easier?
Thanks Jon! No, the target computer does not have .NET installed (at least none more than the ones windows have at default). But it seems like JAVA/JNI can't even load the dll... I will try installing .NET framework and see
.NET/JNI interop was not the difficult part, that is working on my dev comp... It was tricky but not too difficult.
I would suggest that you run FileMon on the computer which is giving the problem, and then try to run your application. After FileMon captures data, you should see all file accesses made by your Java application and see the exact failure which leads to the UnsatisfiedLink error. For example, it may be that some dependency of your JNI DLL is missing on the other computer (this sounds like a good possibility, after security/permission errors).

Categories

Resources