OSGi Remote DS product configuration works only inside Eclipse - eclipse

I'm working on Eclipse STS 2.7.2 with Java JDK 1.6, Windows XP SP3. I work behind a proxy which requires authentication.
I wrote two simple client and server plugins which work using DS and Zookeeper discovery. They refer to an IHello interface bundled in a third plugin.
The server publishes a simple Hello service which returns a string "hello" when invoked on 192.16.23.28:6666/hello and starts Zookeper with VM arguments
-Dzoodiscovery.dataDir=bla
-Dzoodiscovery.flavor=zoodiscovery.flavor.standalone=192.168.23.28:3030;clientPort=3031
xml is:
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="NOLINKALLOWED" name="it.eng.test.remote.ds.helloservice">
<implementation class="it.eng.test.remote.ds.helloservice.HelloService"/>
<property name="service.exported.interfaces" type="String" value="*"/>
<property name="service.exported.configs" type="String" value="ecf.generic.server"/>
<property name="ecf.exported.containerfactoryargs" type="String" value="ecftcp://192.168.23.28:6666/hello"/>
<service>
<provide interface="it.eng.test.remote.ds.hello.IHello"/>
</service>
</scr:component>
the client starts Zookeeper with VM arguments
-Dzoodiscovery.autoStart=true
-Dzoodiscovery.flavor=zoodiscovery.flavor.standalone=192.168.23.28:3031;clientPort=3030
In both cases the OSGi framework is started with the -console -consoleLog -clean arguments.
I then created two separated run configuration for both server and client (Run as->run configurations..) adding all required bundles (most important ones: org.eclipse.ecf.provider.remoteservice and org.eclipse.ecf.provider.zookeeper) and their dependencies.
Based on that configuration I defined two separated product configurations (new->product definition->select run configuration) for both client and server.
Now, if I run them by clicking on the link "Launch an Eclipse application" inside the respective product configuration, everything works. The server publishes the service, the client gets it and shows "Hello" on output. netstat -a | grep 6666 shows that someone is listening on that port and netstat -a | grep 30 shows that port 3030 and 3031 are being used.
Eclipse is configured to use my proxy correctly.
If I export them as an Eclipse product based on the aforementioned configurations (export->eclipse product->select product configuration), I get two folders: client and server.
Inside them there's everything needed to run the applications inside an external OSGi framework, including configuration files for both the framework (config.ini) and the VM (eclipse.ini).
The applications are started with STS.exe -console which opens an OSGi console with all the required bundles installed and started.
Starting the server works, I see someone listening on 6666 and zookeeper reports that the service has been published.
If I start the client, nothing happens. No output, no connections on 3030 and 3031, no errors. It simply does nothing, zookeeper however says it has started discovery.
Using localhost instead of my IP changes nothing, it still works inside Eclipse but not outside.

The exported application had its configuration stored in: ./eclipse.ini and the OSGi framework configuration was in ./configuration/config.ini
eclipse.ini contained the parameters needed by the Java VM for zookepeer to work:
-consoleLog
-console
-clean
-vmargs
-Declipse.ignoreApp=true
-Dosgi.noShutdown=true
-Dzoodiscovery.autoStart=true;
-Dzoodiscovery.flavor=zoodiscovery.flavor.standalone=localhost:3031;clientPort=3030
Launching the application was ok but that file wasn't read.
manually launching the application as:
java -Dzoodiscovery.autoStart=true; -Dzoodiscovery.flavor=zoodiscovery.flavor.standalone=192.168.23.28:3031;clientPort=3030 -jar org.eclipse.osgi_3.7.0.v20110613.jar -console -configuration c:\temp\zooc\configuration\
from within ./plugins where all the jars were worked.
Guess the .exe made automatically by Eclipse wasn't well configured to read its config file.

Related

How to debug on remote AEM server?

While reading online AEM documents, I came across how to run the AEM on debug mode. But How to debug on remote AEM server ?
To use remote debugging, you must start CQ5 with this JVM parameter:
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
You can add the parameter by doing the following;
Start your server like this: crx-quickstart/bin/start -d --debug-port 8000. The -d parameter adds the jvm parameter to the CQ5 java process.
Add it to your crx-quickstart/bin/start script CQ_JVM_OPTS environment variable (so your server always starts in debug mode).
Include it as a parameter when starting CQ5 with java -jar directly. For example, java -Xmx512m -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n -jar cq-author-4502.jar
Just as you would debug any Java application. Open the AEM in debug mode (i.e. add -debug <your port> to the startup parameters) and connect to it using your favorite IDE. I don't remember how you do it in Eclipse, but in IntelliJ you just create a new "Remote" run configuration specifying the debugging port.
i am using Intellij, there you can create remote connection for debugging as shown in below screen shot.
1. use the remote server
2. port on which you are running your AEM instance on Debug mode
Done!

how to setup a debugger for AEM or CQ?

how to setup a debugger for AEM or CQ? I'm using Eclipse IDE and Maven 3.2.5 for build and AEM version 6.0. I'm new to AEM and Java.
This Adobe article walks you through it: https://helpx.adobe.com/experience-manager/kb/CQ5HowToSetupRemoteDebuggingWithEclipse.html
Step 1: Add the Remote Debugging JVM Parameter
To use remote debugging, you must start CQ5 with this JVM parameter:
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
You can add the parameter by doing the following;
Start your server like this: crx-quickstart/bin/start -d --debug-port 8000. The -d parameter adds the jvm parameter to the CQ5 java process.
Add it to your crx-quickstart/bin/start script CQ_JVM_OPTS environment variable (so your server always starts in debug mode).
Include it as a parameter when starting CQ5 with java -jar directly. For example, java -Xmx512m
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n -jar cq-author-4502.jar
Notes
If necessary, you can change the port defined under "...,address=8000,..." from 8000 to something that works better in
your environment.
Starting CQ 5.5, using the last solution, when Quickstart forks a new process it does not start the JVM with the debug options. You can
prevent forking by specifying the -nofork command line option.
Te start script is located under crx-quickstart/server for CQ versions < 5.5
Step 2: Start a remote debugging session
To start a remote debugging session from Eclipse, do the following:
Open Eclipse.
Choose Run > Debug Configurations.
Right-click Remote Java Applications and select New.
Select your CQ5 project under Project.
Type in the port from the "address" configuration of the jvm parameter defined above. In the example, it is port 8000 (and the host
name of the machine you are connecting to, most likely localhost)
To start a debugging session, double-click your new configuration in the Debug Configurations screen after saving it.
Applies to: CQ 5.x and Adobe Experience Manager 6.x
If you're on windows follow these steps.
Open AEM crx-quickstart, move onto bin, open start.bat(Right click and edit), find default JVM options, add the line
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=3000 next to headless=true in the start.bat file, save it. Open cmd in the bin folder. Type start.bat and hit enter which will open the instance with debugging port 3000.
Open Eclipse. Add breakpoints to the java file. Run > Debug Configurations > Remote Java Application, right click and select New Configuration, provide a name, select project(the one with .core), change port to 3000, apply and debug. Change the perspective to Debug, Window > Perspective > Open Perspective > Other > Debug.
Open AEM Page containing the component which uses the java class for which the breakpoints have added. If you’ve added breakpoints for the HelloWorldModel.java, open the page with helloworld component or refresh if already opened. And that’s it, eclipse will notify and the program will be paused at the breakpoint.
Possible Errors you might encounter with:
Failed to connect to remote VM. Connection refused. Connection
refused: connect
The debugger has already started when you hit apply and debug and trying to run the debugger again will get you this error.
Debugger not pausing at breakpoints and no notification in eclipse.
If the instance was already running and you hit start.bat in cmd, you’ll find this unusuality. Close the instance, and enter start.bat(in the bin folder). You’ll find the message below when the instance is ready. It might or might won’t open the browser by its own. So just open the browser and enter http://localhost:[portnumber]/.
SUCCESSFULLY LOADED validation.properties via the CLASSPATH from ‘/ (root)’ using class loader for DefaultSecurityConfiguration class!
RAWProcessor succesfully installed
17.10.2019 12:59:41.437 *INFO * [main] Startup completed
Step1: Start AEM service in debug mode with -debug parameter and a port number.
Step2: Setup debug configuration in IDE with the above port.
References:
How to start AEM in debug mode?
CQ5How To Setup Remote Debugging With Eclipse

run tomcatRun task with debug mode

I've got multiple project which are using tomcat on different ports.
I usually run tomcatRun task simply using gradle tR.
But I need to debug one application - it runs on localhost:9080 port so I created debug configuration in eclipse to use localhost and 9000 port.
But how to run tomcatRun task with debug properties? As a solution I found to use some variable
GRADLE_OPTS="-Xmx2048m -Xms2048m -XX:PermSize=512m -XX:MaxPermSize=1024m -Xdebug -Xrunjdwp:transport=dt_socket,address=9000,server=y,suspend=n"
However I don't get how to set it for my current application - because I've got multiple application which are using tomcat and I want to run only one application in debug mode?
You can use setenv.bat/setenv.sh in tomcat/bin directory and write
set CATALINA_OPTS=-Xmx512m -XX:MaxPermSize=256m ...

How can I run two instances of tomcat 7.0 per eclipse different ports?

Project1: http1.1=8080 ajp1.3=8009; Project2: http1.1=8085 ajp1.3=8010. When I run Project2 in eclipseit starts up ok. However, when I startup the second in eclipse it says tomcat has a problem....this is all after cleaning both projects and a reboot.
As per the screenshot, eclipse complains that "tomcat admin port" 8005 is already in use. Please change this under Ports ( in addition to changing http 1.1 and ajp1.3). I think you had mentioned that the port appears to be readonly. If that is the case, the port could be directly modified in the server.xml located in your workspace.
File location: <>\Servers\Tomcat v7.0 Server at localhost-config\server.xml
Locate the following line in server.xml and modify it. Refresh your eclipse and it should reflect in the UI.
<Server port="8005" shutdown="SHUTDOWN">
For 2nd instance change the server port to some other port like 801010 ...it will work
You need to change all the three port numbers as in the pic

Remote debug Jetty (no mvn, no plugins)

Past scenario
- Work with Tomcat and start in debug mode and Remote Debug with Eclipse.
- Define a port and connect with eclipse in this debug/remote port.
- Use to debug servers in other hosts/servers
Today scenario
Now, I'm using Jetty and I've try to do the same, but with no success, could anyone help-me with that?
I did not use Maven, and did not want to start Jetty inside from my Eclipse.
Environment:
Windows XP
Java V. 5
Jetty V. 6.1.15
Links:
http:// docs.codehaus.org/display/JETTY/Debugging
This did not help me!
http:// docs.codehaus.org/display/JETTY/Debugging+Jetty+with+Eclipse
http:// neelzone.wordpress.com/2007/06/18/jetty-and-eclipse-integration
These are to start inside Eclipse
This is what we are adding to our JBoss command line while development:
-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
Then we launch the eclipse remote debugging and connection to this port.
Update:
To run from jar (standalone) do the following
java -Xdebug -Xrunjdwp:transport=dt_socket,address=8585,server=y,suspend=n -jar start.jar
For remote debugging you should use JPDA. There's a sort of tutorialish article about it available here.
In short, start your JVM with the argument:
-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n
and you are able to connect to the underlying JVM listening on port 8000 via the standard Eclipse debugger.
If you will use mvn jetty:run one day, you have to
export MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n"
appending -Xdebug ... doesn't works
Using the JVM "agentlib" command-line parameter before "start.jar" did not work for me, but this does:
How to allow Eclipse to remotely debug #Jetty (#JPDA #agentlib:jdwp) on port 8000
You have to create a file, $JETTY_BASE/start.ini (do not change $JETTY_HOME/start.ini) and put the following two lines in it:
--exec
-agentlib:jdwp=transport=dt_socket,address=localhost:8000,server=y,suspend=n