Maven equivalent in .NET C# - java

Let's assume there are two Maven Java projects, A and B. A has a dependency on B. B is placed in remote Maven repository and also on GitHub.
In IntelliJ Idea IDE, I will open project A and also B (B is cloned from GitHub) in two separate windows.
Now, B has a class named Car. When I 'Ctrl+Left mouse button click' on class Car in project A, IDE switches me automatically to the source code in opened project B. Therefore I can comfortably work together on A and B.
How can I achieve same behaviour with .NET C# and Visual Studio?

The rough equivalent to Maven in the .NET ecosystem is NuGet. NuGet files can be created using the IDE or command-line tools such as dotnet pack or nuget pack. A NuGet file is just a regular .zip file with the .nupkg extension. These files can be hosted on http://www.nuget.org for the general public to consume, on a site such as http://www.myget.org, or on a private hosted NuGet server.
The NuGet tools also have the ability to create debug symbol packages that contain the source code files. The debug symbol packages can be hosted on public or private symbol servers and used in Visual Studio to step through the code, with the configuration options enabled in Visual Studio.
If you open project A in Visual Studio and automatic package restore is enabled and that project has a package reference to project B, when you build the project it will automatically download the NuGet file for project B, unpack it to your local NuGet cache, and use the assembly for project B in your project.
If Visual Studio is configured correctly to find a debug symbols package corresponding to the exact version of project B, it will allow the debugger to step through the code of project B.
AFAIK, opening the code file of project B and then setting a break point is not possible (someone leave a comment if this is wrong), you need to set a breakpoint in project A and then when you step into the line that calls/instantiates the Car class, Visual Studio will open up the code file so you can step through it.
Update 2023-01-15
Note that the above symbols documentation still works, but there is now a better way. If the author of a NuGet package configures Source Link and the code exists in a Git repository, an IDE can enable source stepping and the code files can be downloaded directly from the repository into the IDE's debugger. This means it is no longer necessary to package source files in the symbols package. This feature uses a Git commit hash to ensure that the source code matches the binary even if you upgrade the NuGet package later.
The symbols have also been updated to allow a .snupkg file by including <PropertyGroup><IncludeSymbols>true</IncludeSymbols><SymbolPackageFormat>snupkg</SymbolPackageFormat></PropertyGroup> in the project file. This new format can be uploaded directly to NuGet instead of having to use a 3rd party symbol or self hosted server for debugging.

Well, actually it is possible. But some MSBuild modification is necessary.
Preconditions:
use the new MSBuild format that was shiped with VS 2017
Step by step:
create a solution and add both projects
I assume project A has a package reference to project B and the nuget package names are the same as the project names
in the root directory of both projects, which is probably not part of any source control system, create a file with the name Directory.Build.targets with the following content:
true
<PropertyGroup>
<SolutionFileContent>$([System.IO.File]::ReadAllText($(SolutionPath)))</SolutionFileContent>
<SmartSolutionDir>$([System.IO.Path]::GetDirectoryName( $(SolutionPath) ))</SmartSolutionDir>
<RegexPattern>(?<="[PackageName]", ")(.*)(?=", ")</RegexPattern>
</PropertyGroup>
<ItemGroup>
<!-- Keep the identity of the packagereference -->
<SmartPackageReference Include="#(PackageReference)">
<PackageName>%(Identity)</PackageName>
<InSolution>$(SolutionFileContent.Contains('\%(Identity).csproj'))</InSolution>
</SmartPackageReference>
<!-- Filter them by mapping them to another itemGroup using the WithMetadataValue item function -->
<PackageInSolution Include="#(SmartPackageReference -> WithMetadataValue('InSolution', True) )">
<Pattern>$(RegexPattern.Replace('[PackageName]','%(PackageName)') )</Pattern>
<SmartPath>$([System.Text.RegularExpressions.Regex]::Match( '$(SolutionFileContent)', '%(Pattern)' ))</SmartPath>
</PackageInSolution>
<ProjectReference Include="#(PackageInSolution -> '$(SmartSolutionDir)\%(SmartPath)' )"/>
<!-- Remove the package references that are now referenced as projects -->
<PackageReference Remove="#(PackageInSolution -> '%(PackageName)' )"/>
</ItemGroup>
</When>
What happens here, is that all package references are automatically dynamically replaced with project references, when they are contained in the currently opened solution.
For further information, i have posted that solution also in a MSBuild github issue:
https://github.com/dotnet/sdk/issues/1151

Related

Can't import class from jar file although it's visible among IntelliJ External Libraries

Like screenshot shows. I have project party-management that uses common-lending-lib. common-lending-lib then uses math2 library.
When I open common-lending-lib project, it can easily detect math2 dependency and use it.
When I open party-management-project, it can detect common-lending-lib, and math2, but during runtime, it fails on functionality that common-lending-lib takes from math2.
What can be the reason? These projects are in Spring Boot, if it matters at all. I use IntelliJ 2017.1.5 and Java 1.8
Can package name be the reason? I have:
party management in org.kd package
common lending lib in org.kd package
math2 in org.kd.math package
Details of the project can be found on https://github.com/LendingBusiness

Build OpenCV with contrib modules and Java wrapper

I'm trying to build OpenCV on my Windows 7 machine. To include the contrib modules I have added the OPENCV_EXTRA_MODULES_PATH in CMake-gui. The opencv-300.jar and opencv-300.dll have been created but I can not find the Java classes to use the extra modules. Am I missing an option in the make configuration? Is it possible to use these extra modules from Java?
i've the same problem and i resolved in this way. I imagine that you had downloaded from contrib repo the specific version match with the opencv version if you want to build. So go in directory and enter, for example, face module directory; in this directory there is a file called CMakeLists.txt that you have to edit. This file should be like this:
set(the_description "Face recognition etc")
ocv_define_module(face opencv_core opencv_imgproc opencv_objdetect WRAP python)
# NOTE: objdetect module is needed for one of the samples
If you want to have the org.opencv.face package in your opencv-3xx.jar library you have to modify the 2nd line of the file in this way:
ocv_define_module(face opencv_core opencv_imgproc opencv_objdetect WRAP python java)
Then you have to compile opencv as depicted in the Readme.md of the contrib repo https://github.com/itseez/opencv_contrib
Obviously the same thing is valid for all the contrib modules if you want to add to your opencv-3xx.jar library.
I hope that this solution works for you, bye!

Oracle Rules - Imported Java Fact causes UndefinedException when deployed

In JDeveloper 12c, I have created a BPM application/project. Project SOA Settings are Composite With Business Rule.
The project has a Mediator and is exposed as a REST service. I am deploying using the IntegratedWebLogicServer
The XML Facts are rather generic including lists of fields, sub-lists, and sub-sub-lists, etc. This makes navigating the inputs more challenging.
I created a Java class with some static methods that more easily retrieve the data based on an expression. I created a jar with that class and then imported the class into the Java Facts. I then created rules that call the static methods on that Java Fact.
The rules validate just fine and I can now successfully run the rules from the "Test" tab of the rules. I get expected results. However, when I deploy the project it seems like the imported jar is not deployed along with it since I get the following exception:
oracle.rules.rl.exceptions.UndefinedException: The symbol "mypackage.MyUtil" is undefined.
at line 22 column 14 in /Ruleset(main)
I thought that importing the class in the Java Facts would cause my custom jar or at least the class that I imported to be deployed. But it seems that this may not be the case. Am I missing something? Is there somewhere in my project that I can place the jar to cause it to be deployed?
I tried adding the jar to the Libraries and Classpath entries of the project. I also tried adding it to a user library located in the project and adding that to the Libraries and Classpath list. But both had no effect.
I am new to JDeveloper and Oracle BPM, so I'm hoping there's something simple I'm missing here.
The solution was to add the jar to this directory:
MyBpmApplication\MyBpmProject\SOA\SCA-INF\lib

Change default java module structure in IntelliJ IDEA

I would like to know how to change the default java module structure in IntelliJ IDEA from:
module_name/src
Where src is marked as 'sources', to:
module_name/src
/main/java
/test/java
Where main/java is marked as sources and test/java marked as test sources.
Is there a way that I can make this the default so I don't have to manually do it each time?
You can create a project set up to your specifications and then save it as a template that will be available when you create a new project.
See the IntelliJ documentation for [Saving Project as Template]
(https://www.jetbrains.com/help/idea/save-project-as-template-dialog.html).
The right way - create a pom.xml and reorganise the source so that it will work with maven. After it - just import pom.xml into Idea, it will recognise maven project structure automatically.
The manual way - use "Module settings" -> "Sources" and manually change the source folders for your structure. See the screen example here http://wiki.jetbrains.net/intellij/File:Project_structure_dialog_left_hand_pane.png

Java class methods do not auto complete in Jython using Eclipse Pydev

I'm using PyDev 2.5 with Eclipse Indigo and Jython 2.5.3b1 . I have a JAR file that contains certain classes which I'm importing to a PyDev (Jython ) project. They seem to work seamlessly except for Auto completion. The member functions of Java Classes do not auto-complete e.g. pressing the dot '.' operator does not bring up the list for class member functions. The jar file is added to the PyDev-PYTHONPATH external libraries of the PyDev project.
Screenshot of PYTHONPATH external libs
Auto completion does not work for the code below, but it compiles and runs perfectly fine.
from my.testpackage import MyClass
myVar = MyClass("Monkey")
print myVar.getName()
Typing "myVar." does not auto complete
Worth noting that auto completion works if I imported a non custom jar
e.g.
from java.lang import Math
print Math.max(3,5)
Typing "Math." will auto complete
I'm not sure if this functionality even supported in the current version of PyDev. Does anyone actually have this working in their PyDev and Eclipse setup?
Any suggestion would be appreciated.
Thank you,
DM
It may be some issue in your PYTHONPATH configuration. Have you read: http://pydev.org/manual_101_project_conf2.html (most specifically the end of the page: "Project reference for Jython users").
If that doesn't help you, can you explain how are you referencing things? (a screenshot with the config would be nice)

Categories