Add external libraries to my project issue - intellij-idea

I try to add external library to my current project, but my project can't pick up the library.
I have MyLib.java file in other directory.
/Users/cat/myfile/github/JavaLib/MyLib.java
I want to my current project (/home/project/HelloWorld/HellowWorld.java) to use my MyLib.java
I'm following the steps to add Library to Intellij(15CE)
Menu->Project Structure->Libraries
click (+) symbol->select Java -> select my path(/home/lib/)
Here is the screenshot

Now that you have added your JavaLib directory to the project you should be able to use the code inside JavaLib in your code now. Intellij should offer auto-complete when you start to type the name of a JavaLib class and automatically include the import for you in your code.
The disabled Apply button you circled isn't an issue. I get that in my view too. It just means nothing has changed that needs to be applied currently.

Related

I don't manage to add a file to my QML project with Qt Creator Qt6

I feel a bit ashamed but I simply don't manage to add a file to my QML project in Qt Creator.
I use Qt 6.2.3 and my build system is qmake.
First off, I created a file MyButton.qml by doing a right click on the folder named QML of a project which only contains a main.qml file.
Then, when I type MyButton in main.qml I can use the autocompletion so I see Qt Creator detects my new type.
But during executation, I got this error :
QQmlApplicationEngine failed to load component
qrc:/MyProject/main.qml:9:5: MyButton is not a type
Anyone knows how to add a file to a project ?
I carefuly followed the official documentation (https://doc.qt.io/qt-6/qtqml-documents-definetypes.html) and several tutorials but nothing works. That's crazy.
EDIT :
I did what JarMan advises but I still get the same error.
Here is an image of my project arborescence
And the content of the qml.qrc file :
<RCC>
<qresource prefix="/">
<file>MyButton.qml</file>
<file>main.qml</file>
</qresource>
</RCC>
I believe the problem you're running into is simply that your executable doesn't know where to find your .qml file because the build folder is usually not the same as the source folder. To fix this, you should create a resource file (you can name it something like qml.qrc) and list all of your QML files in there. This allows the QML file to get bundled into the executable.
An example would look like this:
<RCC>
<qresource prefix="/">
<file>MyButton.qml</file>
</qresource>
</RCC>
Then in your .pro file, add this line:
RESOURCES += qml.qrc
EDIT:
You can do the same thing in Qt Creator.
Step 1:
You might already have a resource file in your project. If so, you'll see it in the Project view on the left side of the window. If you do, you can skip to Step 2. Otherwise, go to File->New File... and select Qt Resource File. Name it qml.qrc (or whatever you like).
Step 2:
Once you've created that file, it should now show up in the Project view on the left. You can right-click on the file name and select Add Existing Files. Choose your MyButton.qml file. That should do exactly what I mentioned in my original answer, but without manually typing any code.
I got the same error with Qt 6.3.1
I found the Qt Creator doesn't generate the qml.qrc file when you select Minimum required Qt version: to Qt 6.2.
So I switched the Minimum required Qt version: to Qt 5.15 in Qt Creator Wizard, the qml.qrc file will generated and my custom component qml file would be included automatically in it.
Also, the .pro configure file has different items between these two Qt version.
Solution 1:
add qml in the pro file:
resources.files = main.qml MyButton.qml
Solution 2:
add a qrc file into project and add qml as resource file

Creating class inside package A of A.B in IntelliJ

I have a maven project in IntelliJ IDE. I have created a package with name event.handlers. After which I created multiple classes inside this package.
There are no classes inside event everything is inside event.handlers.
Now I want to create a java class inside package event.
Is there any way from the IDE I can do that?
Currently, I am manually creating the java file inside the event folder in my code repository.
In the left Project structure pane, there is Settings button, in that please Uncheck, Compact Empty Middle Packages.
The settings will be like
.
Now you will have a tree structure, where you can right-click or (ctrl + enter/ alt + insert) on the package and create the file.
For example,
Try creating a Java Class at src folder named event.NewClass. This will create a NewClass.java inside src/event.
You can create folder with the dot symbol . at creating a Java Class or a Package, or Kotlin File/Class when Type is not File. For example create a Package with name com.company.example at src folder will automatically generate the folders recursively, src/com/company/example, create a Java Class with name com.company.example.AClass will automatically generate a file AClass.java inside the automatically generated folder tree src/com/company/example.
It might be easier to just create the class inside package AB and Refactor > Move to place it inside of A.
It seems that all other answers here are workarounds anyway, so if it's just a one-off, this might be the easiest option.
However, in my case, after doing this I had to "Invalidate Caches and Restart" before IDEA updated the UI properly.

Adding custom code generator

When I work with certain types of files, such as: Java file, HTML file or Jasmine Test file I can generate some useful code snippets using Code > Generate option, for example:
if I am working with Java file Code > Generate allows me to insert getter, setter, constructor etc
if I am working with HTML file Code > Generate allows me to insert an XML tag
if I am working with Jasmine Text file Code > Generate allows me to insert a scaffolding of a test suit or a singe test case
I was wondering if (and how) I can add my own 'generator'. I know I can use Live Templates, but I like the fact that Code > Generate gives me a quick list of all available generators.
Yes, you can do it by writing an IntelliJ plugin and extending this class:
com.intellij.openapi.actionSystem.Action
If you create an intelliJ plugin project (just google intellij plugin developmentfor information on how to get started), hit alt-enter somewhere in your project source tree and select Action, you will get a dialog which allows you to configure where your action should appear.
You want to place it in relation to another action which already exists, for example right below it. In your case - have a look at the menu group named GenerateGroup (Generate).
Once your action is defined in this manner in your plugin.xml, build and run your plugin in the sandbox.
Now, when your action is triggered, the AnActionEvent will be fired which contains references to all the necessary information you need (current project, file, position of cursor within file, psi tree, etc).
Try to get this working so far and come back with any specific questions.
Good luck!

How to set up a multi-module project with equal hierarchy modules in IntelliJ?

I am wondering how to configure the following project layout in IntelliJ:
An Android application
A server back end feeding data to this application
Bean classes that are shared between back end and Android application
Initially, I wanted to create three modules on an equal hierarchy level. However, this does not seem to be possible with IntelliJ. I can only add new modules inside of the first module. I wonder if this is the way I am supposed to do it? Or is there a better way to do configure this project layout with IntelliJ? Do these hierarchies only represent folders?
I feel like I should make (3) a library module and add dependencies to (1) and (2). Since a module is defined as a discrete unit of functionality which you can compile, run, test and debug independently I feel like this is the right approach.
This is my first multi-module project in IntelliJ. Any explanation is appreciated!
When creating a new project you can use the Empty Project option on the first wizard step. When the project is created, add 3 modules in different folders under the Project Structure settings.
If you want to add them on a already initialized project, the trick from #CrazyCoder works, but you must not choose Empty Project, but instead Empty Module (in the Project Structure -> Modules dialog).
Then, choose the existing project.
Lastly, on the right side, the content root might be wrong. Set it to the root of your module.
Make sure the submodules are not on root level on the Project Structure -> Modules page. If they are, remove all expect the root module, delete the content root on the right, and add it again.

After adding new class file to App_Code, build action is Content instead of Compile

In VS2008, I am adding new classes to a web project.
When I right-click on App-Code -> Add -> New Item -> Class ...
The build action for the newly created item is set to content instead of compile. This seems like it would be a problem with the template. I've found several others through google who have run into this issue, but nobody seemed to have found a more permanent solution, other than "change it from content to compile after creation."
My question: Does anyone know of a fix for this, official or otherwise?
App_Code is a special folder meant for folder based projects.
This is just a hunch, but it might be that you have a project file based project, instead of a simple folder based one.