So I have just packaged my JavaFX 8 application using the zenjava maven plugin in eclipse. Unfortunately my application performance outside of Eclipse is abysmal. The application connects to an online database that I have set up and allows users to query items in the database. When I run the application in Eclipse it takes 3-6 seconds to start up, but when I am running commands in it the response is almost instant. Now that I have my jar packaged and running on my terminal it takes at least 10 seconds to start up and responses are frustratingly slow.
I have seen that the option -Djavafx.autoproxy.disable=true has helped many people overcome what seems a similar problem, but when I run
java -jar -Djavafx.autoproxy.disable=true application.jar arg
it is not any faster than it was originally. Most of the other ways I have seen to deal with this is done in Netbeans, which I do not use. Curious if anyone has dealt with this in Eclipse and can provide any insight? Thanks!
Related
I am trying to debug a simple DropWizard application in Eclipse, in an attempt to familiarise myself with it. I can start the jvm from the command line like this:
java -Xdebug -agentlib:jdwp=transport=dt_socket,address=9999,server=y,suspend=n -jar dropwizard-0.0.1-SNAPSHOT.jar server config.yaml
And then connect to it as a remote java app.
Or I can find the application class (containing the main method) in eclipse and launch the application in debug that way.
Both these methods appear to successfully start the application in debug, and sure enough, if I set a break point somewhere, it gets hit.
My problem, however, is that Eclipse would normally at this point give me some control over the application but in this case is rather oddly not allowing me to resume, or use any step commands. I can't do anything other than terminate the application.
Perhaps I am having a stupid morning, but I cannot fathom why this is happening.
Can anyone shed any light on this and how I can gain the control required to debug?
I cannot be certain, but I believe this may have been due to an unintended mix of 32bit and 64bit components.
I had the same problem with a project I was much more familiar with a few days later, and in that case it was resolved by changing the buildpath to use the 64bit JDK. I was previously deploying it to a 64bit tomcat with the 32bit jdk on the build path when this happened.
Clearly the situation is a little different with dropwizard as its deployment is self-contained, but similarly altering the build path there seemed to resolve this for me.
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.
The scenario I am facing is that I am currently developing on a Windows version of Eclipse, which suits all my developing and debugging needs. However, my testing works only on a Linux machine, and I have a plain Linux server where I run my Java code.
So, what I end up having to do is constantly :
build in Eclipse -> export as a Jar -> SFTP to my Linux Server -> SSH to run/test the file
As you can imagine, this gets very repetitive. So I'm just wondering what the best approach to do this. It would be great if you guys help me, or point me in the right direction.
Is Eclipse truly all you're likely to need for the foreseeable future? If there's even a chance you might need a better build technology (e.g. Gradle or Maven both of which can be run from the command line, and so let you script all of the above), I'd bite the bullet and move to it now rather than putting time into figuring out how to cobble something together that works with Eclipse.
You should be able to automate the SFTP upload and the SSH command that perform testing in a batch script that you could run from the command line. (Exact syntax for those two commands will depend on what your SSH/SFTP client is, but if you're using something well-known like PuTTY then I'm sure there's plenty of documentation out there and you can post questions on SO if you get stuck on something.) So really the sticking point is the process of building your JAR, and that's very easy if you move to a better build technology than Eclipse.
Is there any way to avoid the delay caused by the JVM starting up each time you run an exec command in PHP?
I have two JARs for encryption and decryption that I need to run using PHP. Both run on the same script although one decrypts a URL parameter and then the other encrypts some other information. When I run them through the command line, they both finish in less than 0.4 seconds each. However, when I run them using the PHP exec function, a new instance of the JVM is started which adds 5 seconds onto each JAR execution time.
I have investigated using Nailgun but can't get that to work. I can't find any documentation for getting it to run a JAR and when I use classes, it can never find them either.
I have also considered using PHP/Java Bridge. I would prefer however to continue using exec. I am already running IIS 7.5 and I am not sure how one would configure the bridge to work with this.
My question is this: Is there any way to keep the JVM running in the background in such a way that the PHP exec function does not need to start a new instance each time? I think there must be a way as there is no delay through the command line.
If there is no way of doing this, then I am open to other suggestions. 11 seconds to run a PHP script means that visitors to the website will most likely leave.
Additional information that may or may not be of use:
It will be running on Windows Server 2008 R2 32-bit OS.
Local access required only.
IIS server 7.5 being used.
Website is coded in PHP. PHP version is 5.3.5.
Server is running the latest JRE - Java7 u6
Is there any way to keep the JVM running in the background in such a way that the PHP exec function does not need to start a new instance each time?
You can start a ServerSocket on a known port.
If its the first time the application has run, this will be successful and this process can keep running.
If this is not successful, the application can open a Socket on that port and send the command as required and get the response.
Even though the accepted answer mostly resolved my problem, the JAR execution time was still taking slightly too long. I realize that the question deals specifically with the JVM startup time but if anyone else has a similar issue, this may be of help to them also.
I had been generating executable JARs using Eclipse. I was packing the 3rd party JARs inside my JARs. On examination of the generated JARs, I noticed Eclipse had added a lot of it's own classes one of which was in the manifest as the main class (it dealt with loading JARs within JARs I believe). I also noticed that all the files in the JAR were compressed (as you would expect in an archive).
Seeing as my JARs stay on the server machine and are never transferred over the network, I seen the decompression as an additional overhead that could be easily avoided.
I decided to make three simple changes to my JARs based on the info above:
1) Generate the JARs using java command in the command line and write my own manifest. This eliminated the additional class files that were being added by Eclipse.
2) While generating the JARs through the command line, I added the 0 option to disable compression.
3) I did not include the 3rd party JARs in my JAR archives. Instead, I included them in the same folder and added them to the classpath option in each generated JARs manifest file.
This reduced the time it took to run the JARs by ~269%.
We've developed a small app using play!, and it runs standalone on a user's computer (Windows XP or Windows 7), as the users don't have network access. Currently, it runs within a console/command window. I would like to make it so there's no console window in the taskbar where play is running--really, mostly because the users are prone to closing the the window. I came up with a couple of ideas, but I was hoping for some validation or other ideas.
First, I was thinking of running Java via javaw, which is typically what runs for GUI applications running Java--but what would I run? I guess I could run the Winstone Servlet container with the WAR output of play! (mentioned as a solution to the other stackoverflow question below).
Second, I was thinking of trying to wrap it in a windows service.
This question is similar, but slightly different (I don't mind installing play!, which just involves unzipping the framework):
Deploy Play! application as executable jar
Has anyone used either of these techniques, or is there a better way? Pros/Cons/Examples?
Thanks!
Update: Any comments about Winstone? It turns out that due to security constraints, we'll not be able to [easily] create services or scheduled tasks (as SYSTEM). Thanks again.
I have done something similar for a few applications. The steps I carried out are
Create a bat file that launches the play app. This could be as simple as play run or play start
Create a scheduled task that executes on system startup, using SYSTEM as the user profile to run the command as.
This approach has been working on my internal systems for well over a year.
Alternatively you can use yajsw to wrap your play application as a windows service. It works really well and is easy to set up.
The only issue I have encountered is that on one of my box running on Windows Server 8 R2, some of the jobs are duplicated when the scheduler kicks off. I am not convinced it is directly related to yajws and I have not been able to reproduce the error on other environments with the same setup.
I managed to work around it by adding a synchronization block in my doJob method.
Have a look here for info for setting up yajws with play.
I am not sure if play would work on winstone. A list of application servers known to work with play can be found here.
You will need to war your play application with play war myapp -o myapp.war and test it first.
I ended up creating a batch file that runs "play run", and a runnable JAR that calls "start /B runPlay.bat" as a system call. This way, the console window doesn't start up at all. It works great so far. There seem to be a variety of solutions, but this was fairly simple.