I have the following project structure
project-root
--core
---build.gradle
---project.gradle
--web
---build.gradle
---project.gradle
I configured jRebel to run with gradle, so I can start my embedded tomcat 8 with the command gradle tomcatRun
This shows log-output of jrebel and my application starts on the embedded server, but there is no hot deployment when i change java files.
With the IntelliJ JRebel Plugin I created the rebel.xml files for each of the project project-root, core and web. Also I added a rebel.xml inside the web project in the folder web/build/classes/main as described here
Normally jrebel should show at startup that its wachting some folders, but this is not the case on my site, so i guess there is something wrong with my configuration
here the rebel.xml files
project-root (Path c:/project-root/rebel.xml)
<?xml xsd....">
<classpath>
<dir name="c:/project-root/out/production/classes">
</dir>
</classpath>
</application>
core (Path c:/project-root/core/src/main/resources/rebel.xml)
<?xml version="1.0" encoding="UTF-8"?>
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd">
<classpath>
<dir name="c:/project-root/core/out/production/resources">
</dir>
<dir name="c:/project-root/core/out/production/classes">
</dir>
</classpath>
</application>
web (Path c:/project-root/web/src/main/resources/rebel.xml)
<?xml version="1.0" encoding="UTF-8"?>
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd">
<classpath>
<dir name="c:/project-root/web/out/production/classes">
</dir>
</classpath>
</application>
web (Path c:/project-root/web/build/classes/main/rebel.xml)
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
<classpath>
<dir name="c:/project-root/web/build/classes/main">
</dir>
</classpath>
<web>
<link target="/">
<dir name="c:/project-root/web/src/main/webapp">
</dir>
</link>
</web>
</application>
To attach jrebel to my gradle i did the following batch calls before starting gradle tomcatRun
set REBEL_HOME=C:\Users\myuser\.IdeaIC2017.3\config\plugins\jr-ide-idea\lib\jrebel6
set JAVA_OPTS="-agentpath:%REBEL_HOME%\lib\jrebel64.dll"
then calling gradlew tomcatRun starts the tomcat and jrebel
gradlew tomcatRun
2018-01-09 10:24:09 JRebel: Starting logging to file: C:\Users\myuser\.jrebel\jrebel.log
2018-01-09 10:24:09 JRebel:
2018-01-09 10:24:09 JRebel: #############################################################
2018-01-09 10:24:09 JRebel:
2018-01-09 10:24:09 JRebel: JRebel Agent 7.1.3 (201711301108)
2018-01-09 10:24:09 JRebel: (c) Copyright ZeroTurnaround AS, Estonia, Tartu.
2018-01-09 10:24:09 JRebel:
2018-01-09 10:24:09 JRebel: Over the last 2 days JRebel prevented
2018-01-09 10:24:09 JRebel: at least 0 redeploys/restarts saving you about 0 hours.
But when I change some source files, nothing is detected by jrebel, also when i manually called gradlew compileJava
I think that the problem is that JRebel is not attached to the actual process running the embedded Tomcat server. Instead, it gets attached to the Gradle's wrapper process. Try attaching JRebel's JVM argument via the org.gradle.jvmargs option instead.
gradle tomcatRun -Dorg.gradle.jvmargs="-agentpath:/path/to/jrebel/lib/libjrebel64.so"
Additionally, since tomcatRun task makes use of exploded deployment, rebel.xml files will not be necessary. This is because the build output directory is the same as the deployment directory and the changes made in that directory are automatically picked up by JRebel and reloaded.
Make sure to also compile the changes that you made using the gradle compileJava command to do so.
I tried it out personally and it seems to work well. Although it does not output the JRebel banner to the console output, it does let you know when a class file was reloaded.
While the answer by Tiit is correct, I would like to add that when using Gretty, you need to specify the -agentpath:/path/to/jrebel/lib/libjrebel64.so argument in your build.gradle file like so:
gretty {
. . .
jvmArgs = [
'-agentpath:/path/to/jrebel/lib/libjrebel64.so'
]
}
otherwise, by using -Dorg.gradle.jvmargs option, JRebel agent seems to attach to a wrong process when using Gretty launcher.
Related
I'm working on a Spring Multi Module Project.
One of the projects contains some JSON file in a folder called drivers, located
in: <Project>/src/main/resources.
When I first launch the app all the JSON files are correctly loaded, but if I make a change to one of them JRebel keeps on using the old one.
Is there a way to configure it to solve this issue?
Thank you.
Here is the rebel.xml for this project:
<?xml version="1.0" encoding="UTF-8"?>
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd">
<classpath>
<dir name="C:/PathToProject/target/classes">
</dir>
<dir name="C:/PathToProject/src/main/resources/drivers">
</dir>
</classpath>
<web>
<link target="/">
<dir name="C:/PathToProject/src/main/webapp">
</dir>
</link>
</web>
</application>
Change the classpath part to
<classpath>
<dir name="C:/PathToProject/src/main/resources/"/>
<dir name="C:/PathToProject/target/classes"/>
</classpath>
If the application is trying to load a classpath resource, its full name is important(e.g. drivers/myfile.json) as this is what is passed to the classloader. The rebel.xml must specify paths that are classpath roots, not subfolders. For finer control you can use includes/excludes for the dir entry.
Also the paths are checked in order and if it exists in the first one, that is returned even if it's older.
So in your current configuration JRebel would first search for
C:/PathToProject/target/classes/drivers/myfile.json and find the old version there from the last run of maven-resources-plugin copy-resources goal or project build in IDE.
Now if only the order was fixed, the second path is still incorrect as it would look for C:/PathToProject/src/main/resources/drivers/drivers/myfile.json where it doesn't exist.
I have a modular web project and thus I am allowing modules to be a war archive including webapp folder. Using the following rebel.xml works fine on detecting class changes over all modules. But for some reason jrebel does not move when a html or js is changed.
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com"
xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
<classpath>
<!-- appserver -->
<dir name="/home/xx/data/appserver/target/classes/main"/>
<dir name="/home/xx/data/appserver/target/resources/main"/>
<!-- module -->
<dir name="/home/xx/data/as.module.core/target/classes/main"/>
<dir name="/home/xx/data/as.module.core/target/resources/main"/>
<dir name="/home/xx/data/as.module.mqlcore/target/classes/main"/>
<dir name="/home/xx/data/as.module.mqlcore/target/resources/main"/>
</classpath>
<!-- web>
<link target="/">
<dir name="/home/xx/data/appserver/src/main/webapp"/>
<dir name="/home/xx/data/as.module.core/src/main/webapp"/>
<dir name="/home/xx/data/as.module.mqlcore/src/main/webapp"/>
</link>
</web -->
<web>
<link target="/">
<dirset dir="/home/xx/data">
<include name="**/src/main/webapp"/>
</dirset>
</link>
</web>
</application>
EDIT:
Interesting fact is. When I use the commented part of web configuration all three webapp folders are in the log and will be monitored for changes. But the application server can not find all of the webapp files. When I use the second <web> configuration all files are seen by the application server but are not observed by jrebel. I think it is not possible to have multiple directories linked to "/"
Each of the modules eg .war or .jar files need to have their own rebel.xml files. Otherwise all of them will reload same resources and when having different classloaders all kind of weird things can happen.
It is possible to check which instance of the file JRebel actually uses by searching "found resource" from jrebel.log. It should be written something like this
sun.misc.Launcher$AppClassLoader#184be29 found resource: 'cfg/log4j.xml' from 'file:/C:/Projects/testproject/Trunk/edm/target/cfg/log4j.xml'.
It is also seen which of the file changed by loking up lines with Event like this:
[IntelliJFSNotify] Event 'CHANGE' on: 'C:/Projects/testproject/Trunk/edm/target/cfg/log4j.xml'
Usually found resource and changed file paths do not match if the file is not reloaded. If they do match then it is recommended to send absolute path of the file and jrebel.log to support#zeroturnaround.com for investigation.
Ok, the answer is: indeed it is not possible to configure more than one directory under the <web><link target="/"></link></web> configuration. I have now a folder ./target/all-webapp where I smylink (cp -sR) all files via gradle task ... not nice but works ... and thank god jrebel is following symlinks!
I created an app with JavaFx for windows, which is really cool. I can run it from e(fx)clipse, everthing works fine, but I can't make a jar file from the project.
I can export it (Right click->Export->Runnable Jar File). However, if I run the jar on MAC OS X , in the menu bar I get "java" menuitem instead of my application name ,which i really don't like.
I searched for how to hide that menuitem, or just rename it, and I found that I have to rename the "Application title*" in the build.fxbuild file. Now I can't build it.
So this is what I really want: to remove/hide/rename the "java" menuitem in Mac OS X.
If you have any experience, please share it with me. I will be really grateful :) .
I get the following error when I try to run the build.xml file:
[javac] Compiling 22 source files to C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\build\classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] Note: C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\build\src\application\SajátKészlet.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 warning
[copy] Copying 12 files to C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\build\classesinit
-fx-tasks:
[taskdef] Could not load definitions from resource com/sun/javafx/tools/ant/antlib.xml. It could not be found.
do-deploy:
[copy] Copying 20 files to C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\dist\libs
BUILD FAILED
C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\build.xml:217: Problem: failed to create task or type javafx:com.sun.javafx.tools.ant:resources
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
Total time: 22 seconds
**
I use:
-Windows 7 64bit
-jdk 8 u5
-JAVA_HOME is set
-e(fx)clipse (Kepler), I downloaded the All-in-one version (for the lazy link)
Thanks you very much for your help!
You need to setup jdk as jre in Prefereces->Java->Installed JREs, and check it as "separate jre" in External Tools Configuration->JRE in case of Eclipse
Edit:
Run > External Tools > External Tool Configuration
When you new the JavaFX Project, the generated file, build.xml, maybe have wrong file path.
<?xml version="1.0" encoding="UTF-8"?>
<project name="App2" default="do-deploy" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<target name="init-fx-tasks">
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/> <!-- wrong path -->
<file name="${java.home}\lib\jfxrt.jar"/> <!-- wrong path -->
</filelist>
</path>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpathref="fxant"/>
</target>
you have to check that where are the ant-javafx.jar and the jfxrt.jar ?
For example, JDK 1.8 the two files are in the difference place,
C:\Program Files\Java\jdk1.8.0_20\lib\ant-javafx.jar
C:\Program Files\Java\jre1.8.0_20\lib\ext\jfxrt.jar
so now I only find the way to modify by myself...
<?xml version="1.0" encoding="UTF-8"?>
<project name="App" default="do-deploy" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<target name="init-fx-tasks">
<path id="fxant">
<filelist>
<file name="C:\Program Files\Java\jdk1.8.0_20\lib\ant-javafx.jar"/>
<file name="C:\Program Files\Java\jre1.8.0_20\lib\ext\jfxrt.jar"/>
</filelist>
</path>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpathref="fxant"/>
</target>
after modify the files, right click choose the Run as Ant Build!
I have a little better solution with less modification:
This fix path issue (just add ext\ to fix issue)
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/>
<file name="${java.home}\lib\ext\jfxrt.jar"/>
</filelist>
</path>
Before doing this, you need to have a jdk1.8.xxx in your installed JREs list, not the jre included in the jdk package but jdk itself.
Next, in Run\External Tools\External Tools Configuration open the JRE tab and check that Execution environment is CDC-1.1/Foundation-1.1 (jdk1.8.xxx)
That's all !
I know that I'm a bit late to answer this, but so many of us are still struggling with this issue and in my case, I could not find a proper answer at any place.
In my case when I was getting the same issue, I managed to get it to work by going to Run->External Tools_>External Tools Configurations and selecting JRE Tab. I had to change the Execution environment from 1.7 to CDC-1.0/Foundation-1.0 (jdk1.7.0_25) (and CDC-1.1 also works).
Definitely a newb when it comes to ant, so not sure why the lazy install doesn't pick up the path correctly, but hopefully this will come in handy to someone else pounding their head before reaching for the excedrin.
I also got the same issue
<?xml version="1.0" encoding="UTF-8"?>
<project name="App2" default="do-deploy" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<target name="init-fx-tasks">
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/> <!-- wrong path -->
<file name="${java.home}\lib\jfxrt.jar"/> <!-- wrong path -->
</filelist>
</path>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpathref="fxant"/>
</target>
from this removed the .. in the middle like this
--- file name="${java.home}\lib\ant-javafx.jar"---
then i got basedir error
for that i commented the basedir part and also chande the outdir path from ${basedir}
\build/deploy"
outfile="addressApp" nativeBundles="exe"
updatemode="background" >
<!--<fx:platform basedir="${java.home}"/>--> <------ comment Here
<fx:info title="addressApp" vendor="makery.ch"/>
<fx:application refId="fxApplication"/>
<fx:resources refid="appRes"/>
</fx:deploy>
for the above i saw this https://github.com/reds-heig/logisim-evolution/issues/135
After that build was successful and exe file was generated in deploy folder.
Thanks StackOverflow Peeps
What I did on Windows 8.1, Java 1.8.0_192, Eclipse Photon (4.8.0) and e(fx)clipse 3.3.0.
Uninstall all (incremental) Java installations (JDK, JRE)
Install latest (needed) Java JDK with JRE
Set default Java to JDK in Eclipse (Windows -> Preferences -> Java -> Installed JRE)
Set Separate JRE to JDK in Eclipse (Run -> External Tools -> External Tools Configurations)
Clean project
build.fxbuild -> ant build.xml and run
I build my app with the following build.xml
When I click on release/MyApp.app, it won't run!!!
But when I do
java -jar release/MyApp.app/Contents/Resources/Java/helloworld.jar
the executable (a Windows) does come up, meaning the helloworld.jar is built correctly.
But for some reason, the app doesn't know to load it.
<?xml version="1.0" encoding="UTF-8"?>
<project name="App Builder" default="build_app" basedir=".">
<taskdef name="jarbundler"
classname="net.sourceforge.jarbundler.JarBundler" />
<target name="build_app">
<jarbundler dir="release"
name="MyApp"
mainclass="com.test"
jar="helloworld.jar" />
</target>
</project>
Does anyone know what is wrong here?
Thanks
+1 to trashgod. When testing this (from your previous question), my app wouldn't start. It was because the Stub was using Java 6 instead of Java 7 ... go figure. Once I compiled my files down to Java 6, it worked fine.
Also, make sure that you are including all the dependent Jar files...
I used this as my target...
<target name="default">
<delete dir="package" failonerror="false"/>
<mkdir dir="package"/>
<jarbundler dir="package"
name="Cars"
mainclass="testanimation10.TestAnimation10">
<jarfileset dir="dist">
<include name="**/*.jar" />
<!--<exclude name="**/CVS" />-->
</jarfileset>
</jarbundler>
Updated
I downloaded Java Application Bundler from java.net, which seems to be the replacement for Apple's bundler and following the basic instructions from here and was able to build a bundle that was capable of running binaries compiled under Java 7
I'm looking at deploying a web service which I've written in Eclipse to an EAR file. I'm able to export it as a WAR and deploy it on Tomcat all fine and dandy, but the final product won't be on Tomcat, and won't be a WAR file. I'll need to use Websphere as a server, which I have access to and can deploy valid EAR files... if I had an EAR file to deploy.
So long story short, how do I export an EAR file from a Dynamic Web Project in Eclipse?
You need to create an Enterprise Application Project (basically, an EAR) in Eclipse, add the Dynamic Web Project to the EAR project, and then export the whole thing.
for this I use an Ant build script, (you can create a new Ant file in Eclipse, store it in your dynamic web project root and then right click > run on it when you want to run it from eclipse. Something like below. Basically copy your war to a directory, ${earDir} in the script below, and build that to an EAR (an EAR is just a type of JAR) :
<target name="buildEar" depends="init">
<copy tofile="${earDir}/" file="yourWarFile"/>
<copy tofile="${earDir}/META-INF/application.xml" file="localDirectory/application.xml"/>
<copy todir="${earDir}/META-INF">
<fileset dir="localDirectory" includes="was.policy" />
</copy>
<jar jarfile="localDir/something.ear" basedir="${earDir}">
<!-- Define the properties for the Manifest file. -->
<manifest>
<attribute name="Implementation-Vendor" value="Company name"/>
<attribute name="Implementation-Title" value="Application Title"/>
<attribute name="Implementation-Version" value="version and build number"/>
</manifest>
</jar>
</target>
Your was.policy file will be something like this (not good to give all permissions but you can change it later once you have it up and running):
//
// Template policy file for enterprise application.
// Extra permissions can be added if required by the enterprise application.
//
// NOTE: Syntax errors in the policy files will cause the enterprise application FAIL to start.
// Extreme care should be taken when editing these policy files. It is advised to use
// the policytool provided by the JDK for editing the policy files
// (WAS_HOME/java/jre/bin/policytool).
//
grant codeBase "file:${jars}" {
};
grant codeBase "file:${connectorComponent}" {
};
grant codeBase "file:${webComponent}" {
};
grant codeBase "file:${ejbComponent}" {
};
grant codeBase "file:${application}" {
permission java.security.AllPermission;
};
Your application.xml file will be something like this:
<?xml version="1.0" encoding="UTF-8"?>
<application id="Application_ID" version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
<display-name>yourAppName</display-name>
<module id="WebModule_1240219352859">
<web>
<web-uri>yourWarFile.war</web-uri>
<context-root>urlToApplication</context-root>
</web>
</module>
</application>
The ids there should be ok they need to be unique per EAR I believe (or is it server cant remember).
I hope this helps.