I am running a java spring boot application as jar file with DCEVM hot-swap agent. When i change some class files in my jar file the application is not reloading those changes. But If I extract my jar file and run my application as a simple java class file adding all dependencies to class path( like how IntelliJ Idea does) then replace any of the class file it reloads successfully.
Running extracted jar file:
java -XXaltjvm=dcevm -javaagent:path/hot-swap/hotswap-agent-1.3.1-SNAPSHOT.jar=autoHotswap=true -Dspring.profiles.active=local -Dserver.port=8082 -classpath path/jdk1.8.0_191.jdk/Contents/Home/jre/lib/charsets.jar:--jdk-lib-jars:./path/classes:..other-jar-file-path com.company.app.App
after running above command if I am making any changes and recompiling and then replacing updated class file then the changes are detected and my app reflects the changes.
HOTSWAP AGENT: 15:35:55.349 RELOAD (org.hotswap.agent.config.PluginManager) - Reloading classes [com.company.controller.HealthController] (autoHotswap)
I get above log which tells me that class is reloaded. everything works fine.
Running jar file:
java -XXaltjvm=dcevm -javaagent:path/hot-swap/hotswap-agent-1.3.1-SNAPSHOT.jar=autoHotswap=true -Dspring.profiles.active=local -Dserver.port=8081 -jar app.jar
After running If I update the jar file with following command:
jar uf app.jar path/HealthController.class
jar file gets updated but changes does not reflect and there is no log generated.
HotswapAgent does not detect class modification inside jar file. Instead of it you can use extraClasspath config param. Look at http://hotswapagent.org/mydoc_configuration.html how to setup it.
Related
I have made a java project in eclipse that's a runnable jar if I export it.
My structure of my project :
When I export my project as a runnable jar it asks me how I would like my dependencies to be packaged and I choose to put it in a lib folder. So when exporting it exports the runnable jar as well as creates a sub folder with my dependent jar files which I want to be only the 5 jars located in Referenced libraries.
This is the export window :
This creates my runnable jar and then a folder _lib with my other jars.
This works fine but as you see in the first image I also included the Tomcat lib library because some of the jar files in tomcat lib are used by my project.
The problem is that when I export, all the jar files in the tomcat lib get exported to my sub lib folder which I do not want.
Basically I want to deploy my runnable to a server witch will get the dependent jar files from the sub directory lib only those 5 jar files in image (Referenced Libraries). Tomcat is installed on the server so it should point to tomcats lib to get the rest of the jars.
Want my project to use the generated lib folder and then the tomcat lib.
Hope it makes sense what I am trying to ask.
Using Eclipse and java 1.7. developing on windows, deploying to linux running the application via command line on linux box.
What I have done to get this working is on the linux side to start the java runable class another way by specifying the classpath this will give the class you are trying to run the ability to first check the folders that you specify. So in my example instead of executing my app on the linux box with the following :
nohup java -jar /usr/local/P6/StockListShunter/StockListShunter.jar &
I did the following and specified the Class path lib that java should check for .jar file dependencies :
nohup java -classpath :/usr/mylib1/*:/usr/StockListShunter_lib/*:/usr/share/lib/*: stockListShunter.Shunter &
Notice I specified 3 libraries java should check when running my runable class, mylib1,StockListShunter_lib and lib.
After you specified the classpath you will see you need to specify your java class witch will be your main method class. In my example it is stockListShunter.Shunter where stockListShunter is my package name.
Just take note that you should make sure that the class you are trying to excecute is included in one of the jar files that you specified in the classpath otherwise it wont find the class and you will get an error : Error: Could not find or load main class stockListShunter.Shunter
So when you run the command the process will be started, my program is in a loop so the process will be alive until I kill it. If your program should be alive you can confirm it is running by running the following command.
ps aux | grep stockListShunter.Shunter
Where stockListShunter.Shunter is your main class name. This should display all the processes where the command has a stockListShunter.Shunter in it.
If you want to end the process like mine that's in a loop you can run the following command.
pkill -f 'java.*stockListShunter.Shunter'
Again where stockListShunter.Shunter is your main class name. This should kill your java process.
Hope this could help some one in the future.
My groovy (ant1.8.1 for build)project was build in jdk1.5 and now i am making some changes and upgrading to jdk1.8 .
When i build and make jar ,it works fine from the folder where code is in eclipse.
but when copy that jar and try to run get below-
Error :could not find or load main class Run.
Rest all jars are as below(same as used in jdk5)
groovy-all-1.6.9.jar
commons-codec-1.4.jar
commons-httpclient-3.0-rc4.jar
commons-logging-1.1.1.jar
commons-net-2.0.jar
lib/log4j-1.2.15.jar
jtds-1.2.5.jar
httpmime-4.0.1.jar
When you say "run", I understand you mean something like:
java -jar MyJar.jar
You should check your MANIFEST file inside the JAR and make sure your Main-Class is defined as you need.
Main-Class: pakage.name.ClassName.class
And the corresponding pakage.name.ClassName.class exists in your jar file (or is included in any of the libraries accessible through classpath)
Check this anyway Setting application entry point
I am using getdown to create a means to update a java application.
When I have completed this tutorial, I tested if it works on command line as below:
% java -jar c:/downloads/getdown-X.Y.jar c:/netBeans/getdown/src
Thankfully, this works and launches the application. Great.
How do I make a jar file and distribute this?
I tried to make a jar file on this project but it didn't work, this project does not run. When I run this getdown-X.Y.jar on command line.
I think it still using the same file which I created before c:/netBeans/getdown/src. Eventually, it is failing to execute since it is missing the jar file. So, how to make this project into a jar file and distribute it.
I am not sure what OS you are working on.You can do this by creating an executable jar file. Please follow the steps here:
If you want to create a jar file with additional file. Here in below, if you want to create a jar file of imagine src.class with additonal text file with it which is readme.txt
c:\patel\projects\netbeans\getdown\src.class
c:\patel\projects\readme.txt
Run this command: jar -cvfm src.jar readme.txt netbeans\getdown\*.class
which is: c:\patel\projects\jar -cvfm src.jar readme.txt netbeans\getdown\*.class
Now your executable jar file is ready. To run this jar file:
run this on command prompt: java -jar src.jar
I have this project on Eclipse 3.7 (Indigo) and planning to build the *.jar.
I am to build the project by File > Export > Java.Runnable JAR File > Named the filename of the jar file > Finish.
An error always return to me when running the jar file.
Could not find the main class: [package nmame].[Class name of Main class (PSVM) is located].
Program will exit.
In addition, MySQL Connector 5.1 was included as Referenced Library for JDBC use.
How can I resolve and be able to build a jar file that is running as runned on Eclipse as Java Application?
Thanks in advance.
When you export the project try selecting the option :
Copy required libraries into a sub-folder next to the generated jar
This will create a lib folder containing the required dependency libraries ..
You have also to select a valid launch configuration for the program, to make sure that the MANIFEST file will be created with the MAin class attribute populated correctly .
When you run the generated jar you should run it with this command line (READ the MANIFEST.MF) :
java -jar yourjar.jar
or with Main class specified in the command line :
java yourjar.jar MainClass
I use ant for creating .jar files in Eclipse. Works great.
I have a .jar file I am working on that expects the code to be in a .jar file (it looks for .properties files in the same directory as the .jar file) -- the standard Eclipse "Run" and "Debug" menus execute the main() method of a specified Java class... but they do it from the directory containing the compiled class files, not a jar file. Is there a way to change this behavior so Eclipse runs code from the appropriate .jar file instead?
(My workaround right now is to run the .jar file externally, with it suspended waiting for a debugger, per Dave Ray's answer to one of my other questions.)
You could use remote debugging by running your jar like this
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -jar yourJar.jar
And then connecting from your IDE to that port
Yes, you can create a custom "Run Configuration":
Ie, a "Java Application" one, with:
Classpath tab emptied from its default content (the .class directory) and with the jar added
Source tab with its default content (should reference the src directory of the project)
One such configuration can be run or debugged.
(Example of a custom configuration with jars as user entries)
I just found the following link, which describes the whole procedure in order to debug a Java jar remotely.
Debug Java applications remotely with Eclipse
The main parts are:
Target VM acts as debug server
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address="8000" -jar
test.jar
Target VM acts as debug client
java -Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:8000,suspend=y
-jar test.jar
Based on how you run the target vm, client or server, you have to configure Eclipse differently.
Eclipse configuration if you start the target vm as client
Eclipse configuration if you start the target vm as server
The article gives also a gently introduction into the topic.
I would try to make the code more robust, make the properties file location configurable, or just make it load it from the classpath. Then you can just directly add the properties file to the eclipse classpath. Problem Sovled!