Примечание.
Для доступа к этой странице требуется авторизация. Вы можете попробовать войти или изменить каталоги.
Для доступа к этой странице требуется авторизация. Вы можете попробовать изменить каталоги.
The Service Fabric Reliable Services extension for VS Code makes it easy to build Java Service Fabric applications on Windows, Linux, and macOS operating systems.
This article shows you how to build, deploy, and debug a Java Service Fabric application using Visual Studio Code.
Это важно
Приложения Java Service Fabric можно разрабатывать на компьютерах Windows, но их можно развернуть только в кластерах Linux Azure. Отладка приложений Java не поддерживается в Windows.
Предпосылки
This article assumes that you have already installed VS Code, the Service Fabric Reliable Services extension for VS Code, and any dependencies required for your development environment. To learn more, see Getting Started.
Скачивание примера
This article uses the Voting application in the Service Fabric Java application quickstart sample GitHub repository.
To clone the repository to your development machine, run the following command from a terminal window (command window on Windows):
git clone https://github.com/Azure-Samples/service-fabric-java-quickstart.git
Open the application in VS Code
Откройте VS Code. Click the Explorer icon in the Activity Bar and click Open Folder, or click File -> Open Folder. Navigate to the ./service-fabric-java-quickstart/Voting directory in the folder where you cloned the repository then click OK. The workspace should contain the same files shown in the screenshot below.
Создайте приложение
Press (Ctrl + Shift + p) to open the Command Palette in VS Code.
Search for and select the Service Fabric: Build Application command. The build output is sent to the integrated terminal.
Deploy the application to the local cluster
After you have built the application, you can deploy it to the local cluster.
Это важно
Развертывание приложений Java в локальном кластере не поддерживается на компьютерах Windows.
From the Command Palette, select the Service Fabric: Deploy Application (Localhost) command. The output of the install process is sent to the integrated terminal.
When the deployment is complete, launch a browser and open Service Fabric Explorer:
http://localhost:19080/Explorer. You should see that the application is running. Это может занять некоторое время, поэтому быть терпеливым.
After you've verified that the application is running, launch a browser and open this page:
http://localhost:8080. This is the web front-end of the application. You can add items and click on them to vote.
To remove the application from the cluster, select the Service Fabric: Remove Application command from the Command Palette. The output of the uninstall process is sent to the integrated terminal. You can use Service Fabric Explorer to verify that the application has been removed from the local cluster.
Отладка приложения
When debugging applications in VS Code, the application must be running on a local cluster. Breakpoints can then be added to the code.
Это важно
Debugging Java applications is not supported on Windows machines.
To prepare the VotingDataService and the Voting application for debugging, complete the following steps:
Update the Voting/VotingApplication/VotingDataServicePkg/Code/entryPoint.sh file. Comment out the command on line 6 (use '#') and add the following command to the bottom of the file:
java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n -Djava.library.path=$LD_LIBRARY_PATH -jar VotingDataService.jarUpdate the Voting/VotingApplication/ApplicationManifest.xml file. Set the MinReplicaSetSize and the TargetReplicaSetSize attributes to "1" in the StatefulService element:
<StatefulService MinReplicaSetSize="1" ServiceTypeName="VotingDataServiceType" TargetReplicaSetSize="1">Click the Debug icon in the Activity Bar to open the debugger view in VS Code. Click the gear icon at the top of the debugger view and select Java from the dropdown environment menu. The launch.json file opens.
In the launch.json file, set the port value in the configuration named Debug (Attach) to 8001. Сохраните файл.
Deploy the application to the local cluster by using the Service Fabric: Deploy Application (Localhost) command. Verify that the application is running in Service Fabric Explorer. Your application is now ready to be debugged.
To set a breakpoint, complete the following steps:
In Explorer, open the /Voting/VotingDataService/src/statefulservice/VotingDataService.java file. Set a breakpoint on first line of code in the
tryblock in theaddItemmethod (line 80).
Это важно
Make sure you set breakpoints on executable lines of code. For example breakpoints set on method declarations,
trystatements, orcatchstatements will be missed by the debugger.To begin debugging, click the Debug icon in the Activity Bar, select the Debug (Attach) configuration from the debug menu, and click the run button (green arrow).
In a web browser, go to
http://localhost:8080. Type a new item in the text box and click + Add. Your breakpoint should be hit. You can use the Debug toolbar at the top of VS Code to continue execution, step over lines, step into methods, or step out of the current method.
To end the debugging session, click the plug icon on the Debug toolbar at the top of VS Code.
When you've finished debugging, you can use the Service Fabric: Remove Application command to remove the Voting application from your local cluster.