How to add project instead of jar in vscode? - java

I have a gradle wrapper based java project A in which I am using jar of another project B.
I want to debug a code of jar project B while running A.
This was easy in Eclipse as we just need to add project B to current project A in workspace and adjust the import order.
Is there any way to achieve same in VSCode ?

Make project and Jar be stored in the same one folder then open the folder in VS Code. The folder can be a new workspace.
Reference: Workspace in VS Code

Related

Generating JAR on IntelliJ

I have some problems while creating a jar of my intelliJ project. First of all I just do the usual procedure:
Go to project structure
Select artifacts
Create a new one with modules and dependecies
Go to build artifact, build it
Execute it at console with java -jar "ddddd.jar"
So when I execute the project (not the jar) all runs ok, libreries and all works, but not in the JAR.
Terminal of IntelliJ:
My libraries are located in the project like: project>lib>"some jars here">otherjars>"here some jars and respective dll
This is because the "other jars" need the dll to work. I already tried to run them without the .dll but doesn't work without it.
Also I have them in the project on Modules>Dependencies I have the folder selected as a library.
Any help would be appreciated.
Edit 1:
Here I add some pictures about how I have my libraries structured.

How to add project of different workspace into the current workspace in Eclipse

I have two workspaces and I want to use java file as a parent class or you can say extends it from workspace2 to workspace 1 in eclipse, how can I do this?
As I can add project from same workspace but unable to figure out from different workspace.
I dont want to import the project.
Thanks in advance
You can make New File -> advanced options and Link to Folder in the system where the class is
You need to import your project from workspace 2 to workspace 1.
You can reference your project in another workspace in the build path configuration of your project, linking two eclipse project, even if they are in different workspaces.
If you want the code to be available for changes this are your options:
You have to either import the project or create a new workspace that includes them all.
Note that you may extend the java class from the same project or from another project within the workspace, but not from another workspace.
If you are willing not to have the code in front of you available for changes, you may build the first workspace' project into a jar and then use that as part of your other workspace.
Way 1
You can add the second project's src folder to the current project and you can add them in your project.
Right click on project -> Build path - > source tab - > link source
Way 2 :
Make that external project as a jar and add as a dependency.

How to import two projects in Eclipse, like one

I have problem with importing two Java projects in eclipse like one.
I have one zipped file with 7z extension.
Zipped file structure:
trunk ->
Server -> all server files
Datapack -> all datapack files
So, extract files from zipped folder and trying to import trunk folder to eclipse and i get two different projects (Server and Datapack) and i can't apply diff patch, becouse thease two projects should be in trunk folder.
The other suggested answers so far will destroy the configurations that are already in each project. You can avoid this problem by importing the two projects separately and adding one project to the other project's build path. Specifically, try these three steps:
1.) Import both projects separately into eclipse
2.) Right click on the server project in eclipse, select Build Path...Configure Build Path
3.) Add the datapack project to the server project's build path.
You will then be able to access all of the datapack's functionality from within the server project, as if the projects were merged.
This approach will retain any pre-existing project configurations that may be essential to the project function.
you can solve this by creating an empy project ! then copy both folders into sources , like this you have all resources in one project , unless you are using maven then you need to merge the pom.xml files
You should try creating a new project and merge both projects into it.

Adding a Web Project as a jar in an Eclipse Deployment Assembly

The site I'm working on now is made up of several java projects and a main web project A which references them. The IDE I'm using is Eclipse Helios.
What I'm trying to accomplish is adding a new project B to the stack. The project is also referenced by the main one, but is in itself a Web Project. When I add B to the Deployment Assembly of A, when publishing, Eclipse automatically packages it as a war and deploys it to the server's WEB-INF/lib.
I want it to be deployed as a jar, but also keep the project's web nature, as it has some features (and tests) that are run on it. I have ant tasks in place for building a jar out of B, but I don't know how to use them in Eclipse. Also, I'm not sure if it's possible to make Eclipse deploy a jar out of a web project.
I can add the jar manually (as an archive from the workspace), but that would mean that whenever someone cleans all projects, the jar for B would get deleted and not generated, as the build only compiles the classes and the deploy packages them into the war.
P.S. I know the design is poor, but changing it is out of the question as I don't have the authority :).
I found the following solution that works for me on Eclipse Luna
Project B "Project Facets" : select "Utility Module" instead of "Static Web Module" or "Dynamic Web Module"
Project A "Deployment Assembly" : remove "B" and add it another time.
=> The "Deploy Path" of B is now B.jar
The easiest way is: File -> Export... -> Java -> Jar File
To use ant: open project properties, the go to Builders, Click new, selec Ant Builder, etc.
You can do something like this:
Write a shell/batch script that
calls ANT script of project B which creates a JAR file.
and then, it calls ANT script of project A.
Update ANT script of project A, add a copy task. This file copy task will use relative path to copy the JAR file created in step#1 to project A's WEB-INF/lib directory.
In Eclipse, go to External Tool > External Tools Configuration > Program > New Progam and add this Shell/Batch script to it.
Whenever you want to build. Run this external tool from menu.This will ensure
Your build always has the latest of Project B
ANT tasks will stay small.
Adding a Web Project in an Eclipse Deployment Assembly
I did not know any such thing, until Thorbjørn Ravn Andersen pointed this out in another question where I answered. As mentioned there:
What goes in the deployment is determined not by the build path but by the Deployment Assembly entry in Preferences for the dynamic web project.
But, may be, you have already tried this.
Edit#1: fixed grammar
Edit#2: added more info

importing project in Eclipse

Hello I am new to Eclipse (and I am a novice in Java): I am creating a project which should make use of some classes from another project. Do I have to export necessarily this last project as JAR file and add in my project? Are there other alternatives?
There are several alternatives:
If project A depends on project B, and both projects are in the same Eclipse workspace, you can just project B to project A's build path (project properties / build path / project). This has the nice advantage that it will (optionally) automatically pull in project B's JARs, plus updates to B will be used automatically by A, and you can debug into B's code (even using hot code replace).
If A and B are fairly separate, just make B into a JAR (or several ones), then add these to A's build path.
If you have the source of those class files you can just link that source
Or add the other project as a dependent project.
Or create a jar of those classes and add that in lib.

Categories