Eclipse Launched Maven project not using classes in the \target folder - java

I have a project which I am converting from plain Java to Maven.
I used the "Configure -> Convert to Maven Project" option in eclipse.
I removed all jars in the classpath and referenced them in my POM file and built the project
My new classes are built in project/target but when I launch from eclipse, (using the original launcher) , the old classes are in project\bin folder are used.
How do I reconfigure this to use the correct classes ?

Seems that the configuration for output files in eclipse has not change.
Try to change the output of generated files in eclipse manually:
Right click in project -> Properties.
Select "Java build path" and tab "Sources".
At bottom you have a field named "Default output folder". Change it for: <your-project>/target/classes
For example:
Hope it works.

Related

Customizing which files are shown in Netbeans' Project View under Project Files

I'm using Netbeans IDE (Version 13) for Java development.
In the projects view Netbeans shows a tab for "Project Files". This usually contains files like pom.xml, settings.xml and nb-configuration.xml for an opened Java project.
Now I have added some custom files in the same folder directory as the aforementioned files, namely a Jenkinsfile.config as well as a lombok.config file.
I would like Netbeans to show these files under the "Project Files" tab for each project but until now I wasn't able to find a solution for this.
I already added the file type ".config" as a file association for Netbeans and associated it to the MIME type "Properties Files".
Now Netbeans recognizes the files (an even their contents) when in the "Files" view but they are still not shown anywhere in the "Projects" view.
Does anyone have any suggestions?
[EDIT]: Ideally I would prefer a solution that doesn't require installing any plugins from sources outside of Apache (or similar).
Maybe it is even possible to just configure Netbeans to show the desired behaviour.
You can download and install plugin readmeinprojectview, see here how.
Then go to Tools -> Options -> Miscellaneous -> Display more files. Add the files you need to show in the Project tab. In your case they are Jenkinsfile and lombok.
The plugin by default adds the following files to the project tab under the root project node. Without the plugin, NetBeans for Maven-based projects displays ONLY logical folders under the root project node i.e. "Source Packages" or "Project Files"...
Currently you cannot put the files you want under the "Project files" node. Here is the source code of NetBeans for Maven-based project types. As you can see under the "Project files" node goes the following files only:
pom.xml
nbactions.xml
Files that start with nbactions- and end with .xml
nb-configuration.xml
Maven's default settings.xml

Eclipse error "the import com.microsoft cannot be resolved" [duplicate]

How do I import a jar in Eclipse?
You can add a jar in Eclipse by right-clicking on the Project → Build Path → Configure Build Path. Under Libraries tab, click Add Jars or Add External JARs and give the Jar. A quick demo here.
The above solution is obviously a "Quick" one. However, if you are working on a project where you need to commit files to the source control repository, I would recommend adding Jar files to a dedicated library folder within your source control repository and referencing few or all of them as mentioned above.
Adding external Jar is not smart in case you want to change the project location in filesystem.
The best way is to add the jar to build path so your project will compile if exported:
Create a folder called lib in your project folder.
copy to this folder all the jar files you need.
Refresh your project in eclipse.
Select all the jar files, then right click on one of them and select Build Path -> Add to Build Path
Two choices:
1/ From the project:
2/ If you have already other jar imported, from the directory "References Libraries":
Both will lead you to this screen where you can mange your libraries:
Here are the steps:
click File > Import. The Import window opens.
Under Select an import source, click J2EE > App Client JAR file.
Click Next.
In the Application Client file field, enter the location and name of the application client JAR file that you want to import. You can click the Browse button to select the JAR file from the file system.
In the Application Client project field, type a new project name or select an application client project from the drop-down list. If you type a new name in this field, the application client project will be created based on the version of the application client JAR file, and it will use the default location.
In the Target runtime drop-down list, select the application server that you want to target for your development. This selection affects the run time settings by modifying the class path entries for the project.
If you want to add the new module to an enterprise application project, select the Add project to an EAR check box and then select an existing enterprise application project from the list or create a new one by clicking New.
Note: If you type a new enterprise application project name, the enterprise application project will be created in the default location with the lowest compatible J2EE version based on the version of the project being created. If you want to specify a different version or a different location for the enterprise application, you must use the New Enterprise Application Project wizard.
Click Finish to import the application client JAR file.
Just a comment on importing jars into Eclipse (plug-in development) projects:
In case you are developing Eclipse plug-ins, it makes sense to use Eclipse's native bundling mechanism instead of just importing the jar into a plug-in project. Eclipse (or better its underlying OSGi runtime, Equinox) uses so-called bundles which contain some more information than plain jars (e.g., version infos, dependencies to other bundles, exported packages; see the MANIFEST.MF file). Because of this information, OSGi bundles can be dynamically loaded/unloaded and there is automatic dependency resolution available in an OSGi/Eclipse runtime. Hence, using OSGi bundles instead of plain jars (contained inside another OSGi bundle) has some advantages.
(BTW: Eclipse plug-ins are the same thing as OSGi bundles.)
There is a good chance that somebody already bundled a certain (3rd party) library as an OSGi bundle. You might want to take a look at the following bundle repositories:
http://www.springsource.com/repository/app/
http://download.eclipse.org/tools/orbit/downloads/
http://www.osgi.org/Repository/HomePage
Eclipse -> Preferences -> Java -> Build Path -> User Libraries -> New(Name it) -> Add external Jars
(I recommend dragging your new libraries into the eclipse folder before any of these steps to keep everything together, that way if you reinstall Eclipse or your OS you won't have to rwlink anything except the JDK) Now select the jar files you want. Click OK.
Right click on your project and choose Build Path -> Add Library
FYI just code and then right click and Source->Organize Imports
Jar File in the system path is:
C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar
ojdbc14.jar(it's jar file)
To import jar file in your Eclipse IDE, follow the steps given below.
Right-click on your project
Select Build Path
Click on Configure Build Path
Click on Libraries, select Modulepath and select Add External JARs
Select the jar file from the required folder
Click and Apply and Ok
first of all you will go to your project what you are created
and next right click in your mouse and select properties in the bottom
and select build in path in the left corner and add external jar file add click apply .that's it
In eclipse I included a compressed jar file i.e. zip file. Eclipse allowed me to add this zip file as an external jar but when I tried to access the classes in the jar they weren't showing up.
After a lot of trial and error I found that using a zip format doesn't work. When I added a jar file then it worked for me.
Right Click on the Project.
Click on Build Path.
Click On Configure Build Path.
Under Libraries, Click on Add Jar or Add External Jar.
If you are having a trouble on udemy course of chad on springboot for the importing the jar. Then follow these steps.
Right click on the project.
You will see a option of Build Path, click on it.
You will have a option of Configure Build path, click on it.
Go to libraries.
Then go to the place where you have a jar files make them into a new folder and upload on a new place.
Then click on Add External Jars, you will surely be able to upload it which will help on classpathxmlapplicationcontext as well.
Thank you.

Add .jars in alternative folder

I am new to Eclipse and Java, and I know that .jar files I need to add into libs derectory so that compiler could recognize them. How I can add .jars not only in libs folder but also in other folder too. How can I configure Eclipse to do that?
It's easiest if you have the jar files visible in the package explorer to start with, i.e. within your project directory. At that point, you can just right-click on the jar file, go to the "Build path" section of the context menu, then select "Add to build path".
If the jar file is elsewhere and you don't want to move it, you can right-click on the project, and under the "Build path" part of the context menu, select "Add external archives...". Then find the jar file in the file browser, and hit OK.
All of this can also be done from the project properties dialog, in the Java Build Path section.
Right Click project
Select Properties
Select Java Build Path
Under Tab Libraries Click on add jars or add external jar to add the required jars
The Java build path is used while compiling a Java project to discover dependent classes . It is made up of the following items:
Code in the source folders
Jars and classes folder associated with the project
Classes and libraries exported by projects referenced by this
project
Our goal is to feed our classes with the dependent classes present in the jars during compile time. Eclipse provies with number of easy ways to do it .Here you can find a good article about how to add the jars in the projects with screenshorts attached to it http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)

I used m2eclipse plugins in eclipse.why the imported package still cannot be resolved by eclipse?

I get a mvn project , and to debug this project in eclipse,I imported the project into eclipse.But it's a pitty that some imported packages cannot be resolved by eclipse.Othes tell me that I should install m2eclipse plugin for eclipse, and run ""mvn eclipse:eclipse" to convert the project as a eclipse-like" project ,thus all packages will imported to eclipse build path automatically. Yes , I do so. And the eclipse build path is just like this
:
But it is extremely strange that eclipse still cannot resolve some import .
Any body can tell me what happened? From the build path ,I can see that eclipse have already imported the needed jar file for me.But it seems that the build path didn't take effect.
First of all, you're not using the m2e plugin; while it may be installed, it's not activated for this project:
There is no little "M" on the project's icon
The classpath doesn't include an entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER
From what I can see, Eclipse can't resolve the dependencies since the variable M2_REPO isn't defined (if it could, you would see the absolute path to the JARs in the upper image after the symbolic path).
To fix this, go to Preferences and search for "Classpath Variables". Add M2_REPO there with the correct path (default is $HOME/.m2/repository).
If it already exists, make sure the path is correct.
Alternatively, right click on project and select "Convert to Maven Project" under "Configuration".
How did u create a project. Try creating a web project. This template will provide the correct creation web application structure. It will also automatically add the required jars in the build path.
It is an eclipse problem (are you using the latest version?), try to run:
mvn eclipse:clean
mvn eclipse:eclipse
then open eclipse, refresh the project (right click on the project icon and select refresh),
clean it (Project > clean ...). It could be necessary to reconvert the project to maven
(right click on the project and convert it to maven project).
Sometimes closing the project (right click on the project icon > close project) and reopening it (double click on the icon) solves this issue.

Use Java source dirs from ant build.xml to configure Netbeans project

I have an existing Java project with an ant build.xml and I'm trying to use Netbeans as my IDE.
In Netbeans I've created a new Java Free-Form Project and pointed it at my ant file. This works fine for building, running, etc. However code completion does not work unless I manually add all the java sources for my project (that are already defined in my own build.xml!) via the Netbeans project properties "Java Sources" tab. This is very tedius because this project has has many source dirs.
Is there a way to get Netbeans to recognize the source dirs that are already defined in my ant build.xml to get functionality like autocomplete working?
Netbeans stores the project information in project.xml file not to modify build.xml.
You can set code completion for your case. For this:
- do right click on your project and select ‘Properties’
- click on ‘Java Source Classpath’ in ‘Categories’ panel
- check ‘Separate Classpath for Each Source Package Folder’
If you want to add new source folder select ‘Java Source’ in ‘Categories’ panel and then click on button ‘Add Folder...’

Categories