jvm-sandbox实战之windows调试

由于jvm-sandbox目前只提供了shell脚本来进行运行安装部署,对于mac电脑比较方便,但是windows的方式的话比较痛苦,走了很多弯路,慢慢深入了解之后发现windows的方式也是可以去做的。

1. 下载安装包

细看sandbox提供的一些脚本可以发现,其实脚本里的内容就是想把本地的项目结构打包成:

├── bin
│   ├── attach-pid.sh
│   ├── sandbox.sh
│   └── z-demo.sh
├── cfg
│   ├── repeater-config.json
│   ├── repeater-logback.xml
│   ├── repeater.properties
│   ├── sandbox-logback.xml
│   ├── sandbox.properties
│   └── version
├── example
│   └── sandbox-debug-module.jar
├── install-local.sh
├── lib
│   ├── sandbox-agent.jar
│   ├── sandbox-core.jar
│   └── sandbox-spy.jar
├── module
│   └── sandbox-mgr-module.jar
├── provider
│   └── sandbox-mgr-provider.jar
├── sandbox-module
│   ├── repeater-module-1.0.0-SNAPSHOT-jar-with-dependencies.jar
│   ├── sandbox-debug-module-1.3.3-jar-with-dependencies.jar
│   └── sandbox-manager-module-1.3.3-jar-with-dependencies.jar
├── sandbox-my-demo.jar
├── start.sh
└── z-demo-1.3.3.jar

如果你不想重写那一套shell脚本的话,可以手动构建这些模块,当然它也提供了一套已经打包好的方式,你可以下载

下载完成之后解压到对应的目录就行了。

2. 打包依赖

我们可以内部写一些模块,然后通过maven打包之后,安装包目录的lib下进行替换,比如:

├── lib
│   ├── sandbox-agent.jar
│   ├── sandbox-core.jar
│   └── sandbox-spy.jar

这三个包,在源码模块下的target模块下找到如:

  • sandbox-spy-1.3.3-jar-with-dependencies.jar 替换成 sandbox-spy.jar
  • sandbox-core-1.3.3-jar-with-dependencies.jar 替换成 sandbox-core.jar

3. IDEA 通过 agent启动

比如你有一个SpringBoot应用,那么在运行配置上加入如下配置:

-javaagent:E:\\study\sandbox\\lib\\sandbox-agent-1.3.3-jar-with-dependencies.jar

img

基本上沙箱环境已经差不多可以了.

4. 加入自定义的模块

你可以将他的debug模块放入安装包解压的sandbox-module 目录下进行调试,在启动的时候,agent的执行过程会经过sandbox-module下找对应的插件包.

你只需要打断点就行了.

img

还有如果启动的时候打断点,请在实现了*LoadCompleted*接口的类中loadCompleted方法去操作,因为该接口是沙箱环境启动的时候会回调初始化的。

其他的像debug模块的很多方法需要手动调用才会进入,初始化的时候不会进入。

需要注意的是,你每次写完代码并且编译打包之后,需要移动该包到sandbox安装包的sandbox-module的目录下,不然会出现源码断点对应不上的问题。

提供一个自动拷贝jar的maven插件,在你每次打包时,会将对应的包打到安装包目录下更方便。

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>1.8</version>
      <executions>
        <execution>
          <id>copy-lib-src-webapps</id>
          <phase>package</phase>
          <configuration>
            <tasks>
              <copy todir="E:\\study\\sandbox\\sandbox-module" overwrite="true"><!--执行复制操作,todir的值是将要复制jar包到的地方,overwrite是否重写-->
                <fileset dir="${project.build.directory}"><!--${project.build.directory}值是你的target目录-->
                  <include name="sandbox-manager-module-1.3.3-jar-with-dependencies.jar"/><!--target目录下的jar包-->
                </fileset>
              </copy>
            </tasks>
          </configuration>
          <goals>
            <goal>run</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

另外如果调试的时候发现任何问题切记一定要查看日志,日志一般不会打印在控制台,在windows的

C:\Users\liukx\logs\sandbox 用户目录下。找到sandbox.log日志瞄两眼。

  • 懵逼的时候切记多看看。

  • 懵逼的时候切记多看看。

  • 懵逼的时候切记多看看。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值