I've tried adding .jar files to the Global Libraries section in settings, but whenever I create a new project, those libraries still have to be manually added to the project.
I've consulted the documentation on Jetbrains's site (https://www.jetbrains.com/idea/help/configuring-project-and-global-libraries.html) and I seem to be doing everything correctly.
With only the Welcome to IntelliJ IDEA window open, I've performed the following steps:
Open Default Project Structure options with CMD+;
Select Global Libraries from the left pane.
Click the + in the second pane and select Java.
Navigate to and select the jsoup-1.8.2.jar file which is the library I am attempting to make global and then select OK.
Click OK to close the Default Project Structure options window.
Select Create new Project
Select Java from the left panel and then select Next.
Select Next again.
Name the project and select Finish.
At this point the only External Libraries added is <1.6>.
So I have to proceed by manually adding the library to the project.
How do I set IntelliJ IDEA to load specific libraries automatically when creating new Projects?
Global libs are "global", so it can be used in multiple projects, so the real question is How does IJ know if you want to use this global lib in to "this" project ?
b/c the way "global libs" woks is you could have python virtual-env as global lib, you could have django libs there.. any named-custom set of jars could be a global lib etc..
so how does ij know-- you need python or django etc in this project? that's why you have to tell/add it manually deciding which one is needed for this project.
Related
I need some help with IntelliJ. I am fairly new to programming, and I have some experience with the IDE but I am by no means a know-it-all when it comes to IntelliJ.
I have 3 Java files (without their respective class files). When I open intelliJ it asks me:
Create New Project
Import Project
Open
Check out from Version Control
I click on open, IntelliJ opens up a file location, I click on one of the three Java files to open, and I drag the other two one by one (they open in their separate tab).
I cannot figure out how to run them. It is likely that I need to create run configuration and I don't know how to do it. I know how to create a new project and get everything working, but I don't know how I can get the files working if I just open them. Can someone tell me how to create the run configurations to run the files? Please and thank you.
IntelliJ IDEA is a great IDE!
This is what I would do:
Select File/New/Project... in the menu. You will get a new modal window.
Then select Java on the left, make sure that you have your JDK selected (top right), it not there, create it right from the window. Click 'Next'.
Just go 'Next' on the 'create project from template' step.
Then type your project name and select a folder for it. It will create a new project.
After that, copy your java files into /src folder using drag-and-drop in IDEA or just a file manager you like.
Now you have an IDEA project with your source code in it. You might need to sync your IDEA project, use File/Synchronize for that.
Finally, you can right click on you java file and 'Run' it from IDEA.
It the project fails on compilation you might need to add required imports and libraries, but that depends on your code. IDEA will highlight all the errors.
This is honestly a tiny problem but it's keeping me from proceeding with my small Java practice app.
I'm currently practicing making an API call in Java. I was trying to create a simple class file called "Film". However, when I try to create it as a class-file, Intelli-J keeps telling me that it is unable to create a class-file. I'm trying to set this file up in a folder called "models". All of these class files are going to be utilized as part of an app that performs API calls.
Is there some naming convention I haven't followed? I've been Googling but haven't really found anything.
More directly, based on what #Vishal Jumani touched on, you need to tell IntelliJ what directories are 'source' or 'test' directories.
A directory structure you can use as an example, but you can use whatever you wish.
Right click on the directory you wish to mark as 'root' --> find 'Mark Directory As' --> Select 'Sources Root'
Now you should be able to add java classes in the directory without IntelliJ interrupting you!
This would usually be because of the way your project is setup. It may not be setup correctly to indicate where your source code is.
To setup your project, in the Project Tab, click on the top most folder and select F4. This should bring up the Project Settings dialog window.
Now click on Modules in the LHS, and then select the Sources Tab on the RHS
Select your src folder and click on the Sources button, to indicate this is your source folder. Now IntelliJ is aware that this is where your code is.
Click on Apply and OK. This should close the Dialog Window.
Now right click on the src folder and then select New -> Java Class to create your Java class
What's the difference between Library tab and Order And Export Tab?
I have imported some external jars by adding them in the Library tab. Then they appeared in the Order and Export tab. If I check the boxes on this last tab, I get a duplicate resource error when running my application.
So, what is the purpose of that boxes?
The user Library tab is used to:
Define personal librairies by adding, editing and removing Jars to this personal library, the purpose here is that you don't have to always import all the jars in every project build-path, you just need to put them in a user library(once) and then include this personal library to any project build-path.
And the Order Export/import tab:
Is generally used to set the order of how your librairies will be parsed by the Java Compiler.
Because in some cases the order of Librairies is important and may cause problems.
Take a look here for more information:
User Libraries Preferences
Java Build Path-Order and Export tab
Reading from eclipse user guide
A user library is a set of JAR files. A user library can be added to a projects build path through the build path properties page. The User Libraries preference page allows to define, edit, import, export, or remove user libraries.
Order and export tab is mainly used to export jars to other dependent project. For an example, suppose I have two projects . Project1 has sample.jar added in its libraries, hence it can directly reference and use its resources. There is another project2 dependent on project1 which also needs sample.jar, so either I check the jar in project1's Order and export tab , or add it in project2's libraries. Note that this feature is useful when there are many dependent projects in your workspace.
It is also used to specify the order (by moving libraries up and down) ,as the order of resolution for resources used during project build.
I'm new to Eclipse and Swing. I wanted to use some Data Binding for my program, and saw here [http://help.eclipse.org/juno/index.jsptopic=%2Forg.eclipse.wb.swing.doc.user%2Fhtml%2Ffeatures%2Fswing%2Fdata_binding%2Findex.html][1]
In order to use Swing Data Binding (JSR 295), you must first add the Swing Data Binding jar (e.g., beansbinding-1.2.1.jar) to your classpath
How do I do that? I couldn't google it out...
One thing you can do is download the jar file itself from http://mvnrepository.com/artifact/net.java.dev.beansbinding/beansbinding/1.2.1
Then, right-click on your project in the Package Explorer and select Build Path -> Configure Build Path... Select the Libraries tab and then click Add External JARs... Navigate to the location you downloaded the jar file to and select it; now it's in your build path.
Note: If you already had a class open in the WindowBuilder when you did this, you'll have to close it and then reopen it in order to see the Bindings tab.
Hope that helps!
For a newly created project B, I need to build the path the exactly same way as an existing project A. After opening the “java build path” window by clicking “build path--> configure path”, I found that There are a lot of libraries involved in Project A. How to handle this kind of scenario? Add those jar files one-by-one?
If you can locate all those jars on your file system/network, the best thing for you to do is to create an eclipse User Library.
Creating a Library
Window >> Preferences >> Java >> Build Path >> User Libraries
Select New
Give your library a name
Ok
Select Add Jars
Add all the jars you need for your library
With this library created, you can share the same jars between projects easily by importing the library as opposed to each individual jar file.
Importing a Library
For each project that needs a particular library all you have to do is import the library.
Open the project's properties
Select Java Build Path
Select Libraries tab
Select Add library
Select user Library
Select your Library you created
Finish
Note
User Libraries do not belong to projects, they belong to the User but can be referenced by multiple projects.
Using libraries allows you to update your jars only once for all projects that share the same jars.
I hope that helps :D
If you are using Eclipse and you want your new project to have the exact same libraries/dependencies as a previous project, you can copy the appropriate contents of the .classpath file from the old project to the new one.
This would include any classpath elements with a kind="lib" attribute. You may have to update the path attribute if the location is relative.
This assumes you aren't using something like Maven for dependency management...
There are 2 options:
Create a User Library.
Window > Preferences > Java > Build Path > User Libraries
The good thing about this is, you can re-use it provided you need exact set of libraries for other projects.
Bad thing is, if you want to add new JARs to this, you have to modify it. And modifications is .....not difficult, but takes time. Also, if you need slightly different set of JArs for different projects, then either you have to add some not-needed JARs in either/both projects or you have to add this User Library + some external JARs.
EDIT 1
Go into the Eclipse preferences > Java > User Libraries. Click on "New.."
Choose a name for your user library. Leave the "System Library" checkbox unchecked. Push "OK".
Select your library and click "Add JARs...". Navigate to the location where you put the library.
For each JAR file, there are 4 additional parameters you can attach to the JAR: Source location, Javadoc location, Native library location, and access rules. Except the rest 3, Native library location is not an optional field, and must be included if the JAR requires one
OR
Simply add as External JARs.
Good thing: Simple, straightforward.
Bad thing: If you need too many jars, you have to keep track of each separately.