Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the same launch configuration for more than one Java target #4257

Open
sj-raima opened this issue Jan 27, 2025 · 2 comments
Open

Using the same launch configuration for more than one Java target #4257

sj-raima opened this issue Jan 27, 2025 · 2 comments
Labels
more info needed More info is needed from the community for us to properly triage and investigate.

Comments

@sj-raima
Copy link

sj-raima commented Jan 27, 2025

Brief Issue Summary

Background: We have a large number of Java examples. We would like one launch configuration to cover them all.

For one of the examples we have the following CMakeList.txt (some details are not shown):

CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "")

project (java01Example VERSION 0.99 DESCRIPTION "A simple Java example" LANGUAGES Java)

find_package (RDM 16.1.0 REQUIRED)

find_package(Java 1.8)
include(UseJava)

add_jar(java01Example ENTRY_POINT java01Example_main
  MANIFEST ${CMAKE_CURRENT_BINARY_DIR}/CLASS_PATH.txt
  SOURCES java01Example_main.java
)

The jar target can be executed using the following command
(the class path and the main class has been embedded into the jar file's manifest):

java -jar java01Example.jar

We can launch this with the following launch configuration:

"launch": {
        "configurations": [
            {
                "type": "java",
                "name": "Debug RDM Java Example",
                "request": "launch",
                "args": "",
                "vmArgs": "-jar ${command:cmake.buildDirectory}/java01Example.jar",
                "cwd": "${command:cmake.buildDirectory}"
            }
        ]
    }

There are two issues with this launch configuration that CMake Tools is not able to accommodate:

  1. The target is not automatically built when launching
  2. The launch configuration is not generic as it is tied to one particular example

We would like java01Example.jar in the launch configuration to be replaced with a variable that expands to the selected build target and the target should also be built.

For our C/C++ examples this is not a problem as we can use ${command:cmake.launchTargetPath}. However, for Java there is no way to accommodate this as far as I can tell. Since we have several examples, we would like to have one launch configuration to cover them all.

CMake Tools Diagnostics

Debug Log

Additional Information

No response

@sj-raima
Copy link
Author

sj-raima commented Jan 28, 2025

This launch configuration can be used to resolve the second bullet point:

            {
                "type": "java",
                "name": "Debug RDM Java Example",
                "request": "launch",
                "args": "",
                "vmArgs": "-jar ${command:cmake.buildDirectory}/${command:cmake.buildTargetName}.jar",
                "cwd": "${command:cmake.buildDirectory}"
            }

However, this will not do a build. Using ${command:cmake.launchTargetName} does not work either since this is a target created using add_jar.

@Amy-Li03
Copy link
Collaborator

Amy-Li03 commented Feb 7, 2025

Hi @sj-raima , we are sorry for the delay in responding to you.
Referring to your description of the problem and code segment, I have generated java01Example.jar after building project, however when using the launch configuration you provided, there are some errors as below video, please let me know if I'm missing something or doing something wrong.
Also, it would be better if you could provide a detailed repro step and a minim repro demo project.

Image

@Amy-Li03 Amy-Li03 added more info needed More info is needed from the community for us to properly triage and investigate. and removed triage labels Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info needed More info is needed from the community for us to properly triage and investigate.
Projects
Status: Blocked
Development

No branches or pull requests

2 participants