Java - setting classpath - java

My sample application tells me:
No 'qtjambi-deployment.xml' found in classpath, loading
libraries via 'java.library.path'
I wish for my application to use the qtjambi-deployment.xml, but unfortunately can't find the appropriate setting in IntelliJ IDEA 10.5.
Could someone help me?

You can right click on any directory in your IntelliJ project, select "Mark Directory As...", and choose "Source Root". That director folder will change color from yellow to blue; IntelliJ considers all those directories to be in your CLASSPATH.

From the top menu click 'Run' => 'Edit Configurations'
Choose the right 'Application' in the left column (if it's not yet selected)
Click on 'Configuration' tab in the right hand side column (if it's not yet selected)
Click the '...' button to the right of 'Environment variables:'
Click the '+' button.

qtjambi-deployment.xml file is situated in qtjambi-win<architecture>-msvc<year>-<vertion>.jar. Add this package to your classpath and your building problem will be solved. I hope)

Related

Unable to find or load Main Class in Intellij 2019.4

I have been at this problem for a few days now, don't know why it is still happening. I have tried other solutions that have been posted on stackoverflow but no luck.
Below the following code is from the book crafting interpreters in java.
In IntelliJ 2019.4 this error always pop up when I am trying to run the .jar file.
Error: Could not find or load main class com.jam.Jam
Caused by: java.lang.ClassNotFoundException: com.jam.Jam
I have built the .jar file and setting the main class as com.jam.Jam and the class path for the .jar file as /home/username/Jam-Programming_Language/src/com/jam/Scanner.Scanner.
This is the layout of my project directory.
The following solutions I have tried:
Solution 1
Open Project Structure
Select Modules, then click on the module for which you want the
dependency
Choose the Dependencies tab
Click the '+' at the bottom of the page and choose the appropriate
way to connect to the library file. If the jar file is already
listed in Libraries, then select 'Library'.
and
Solution 2
Go to the Project Structure, click on Modules, and click on your
Module
Choose the "Dependencies" tab
Click the "+" button on the right-hand side and select "Jars or
directories..."
Add the directory(ies) you want (note you can multi-select) and
click OK
In the dialog that comes up, select "classes" and NOT "jar directory"
Make sure you're using that Module in your run target
It had no effect apparently. Any clue on what I should do?
Edit: Uploaded wrong screenshot, replaced screenshot.
Thanks to CrazyCoder for pointing out the errors in my project (silly mistakes). It seems that after I have resolved those mistakes.
I had to follow the solutions I have posted then rebuild the .jar file.
Afterwards I need to mark the src folder as a source root folder (right click folder -> Mark Directory as -> sources root)
Edit Configurations if pointing to wrong main class.
Set Project compiler output (File -> Project Structure -> Project) to a folder designated to hold the output (any folder basically in or outside the project).
The error says, it is trying to run: com.jam.testfile. Your class is called: com.jam.Jam.
Click the dropdown where it shows "testfile" with a little red X on it. Select "Edit Configuration." For the "Main class", select "com.jam.Jam". That's it!
BTW, the little red X means there is some problem with your configuration.

Intellij right-click 'New' is not showing 'Class'

Related: IntelliJ does not show 'Class' when we right click and select 'New'
In the above accepted answer, it says the "New" does not give the option for Java Class because it was not the source root (blue directory).
However, as you can see, even though where I am right-clicking is source root, indicated by blue box, it is not giving me the option for Java Class
Any idea why?
This directory is imported from git so it did not follow the usual "Create Project" for java directly from Intellij
You are right clicking in the wrong spot -- youre "too high" up the tree. Go to where you code is (as in the package under "src") and try it there and you will see the option for a New Class.
EDIT: You don't need to be in the source root. You need to be in the source directories themselves. The blue dot I believe is a git status indicator. What you want is an entirely blue folder.
Go down under "src". Likely under "src" then "main" then "java", and you're there (that's blue for me) and then you will see your package folders. Below those are where you likely want to be adding classes.
As many mentioned above you can right click on the folder you would like it in. In your case:
If you push Alt+1, it might be easier for you to right click
src > New Java Class
Alternatively you can push:
Alt+1 (Project View)
Alt+Ins
or
Ctrl+Alt+Ins
1) Right click on src
2) Click New > package
3) Name your package and press OK
4) Right click the newly made package
5) New > Java Class
If the folder where we are trying to create the class is not marked as source or test then the option is not available.
Right click the project and go to project structure then under project settings -> Modules, Select the folder where you wanted to create class and mark as Source or Test appropriately and then click apply and ok.
Now you will see the change of color of the folder/package(Sources->Blue, Test->Green) and you will get the option to create the class.
This worked for me.
I know this is an old thread, but it happened to me because my gradle files were not synchronized. So if you are within a team working on same project and face this issue, make sure to run gradle sync.
You should go inside java project then you can create java class.

Cannot be resolving in JAVA

I'm new in java and found this after importing project
How can i solve it?
Go to Window > Show View > Other.... Choose General > Problems or search for Problems and add it. Look for the exact reason for red marks on your packages.
Update
Looks like your source folder is misplaced. Follow the steps below:
Right click on the project, go to Properties
Choose Java Build Path on the left pane.
Click on <Project_name>/src and click Remove
Click on Add Folder, choose check boxes (if found) java & resources under the trees src>main and src>test
Click OK and then OK on Properties dialog.
Image reference:

Why isn't intellij giving me the option to create new classes?

Here's what I'm seeing:
Normally I can choose "New Java Class" but for some reason I'm not getting this option. I created this project by opening an empty directory and building it out from there. I've seen this question, but that answer didn't help me. Here's my module settings:
Even if I open my pom.xml directly as a project, it still has this problem. How do I fix this?
The directory or one of the parent directories must be marked as Source Root (In this case, it appears in blue).
If this is not the case, right click your root source directory -> Mark As -> Source Root.
For some reason, intellij didn't recognize my directories as packages. If I created something directly from the java directory, it would give me the correct options. I fixed this by deleting everything under java/ and recreating it. This may be an intellij bug.
This happened when I was trying to add classes to a generated package using xjc plugin.
Intellij allows to add classes only to packages which are correctly names and have the "source root" status.
Can be fixed as-> right click on the directory where you're not able to add classes:
Mark sources root
refer image for clarity
This worked for me :
Right click the java folder (myproject/src/main/java)
Click "Mark Directory as"
Click "Source Root"
Right click the myproject folder (myproject/src/main/java)
Click "Mark Directory as"
Click "Source Root"
So basically had to mark some inner folder as Source project and alter mark parent project again as Source project..
Hacky way but this worked for me.

How to add directory to classpath in an application run profile in IntelliJ IDEA?

I'm trying to add a directory to the classpath of an application run profile
If I override by using -cp x:target/classes in the VM settings, I get the following error:
java.lang.NoClassDefFoundError: com/intellij/rt/execution/application/AppMain
Any idea on how to add a directory to the classpath for my project?
In Intellij 13, it looks it's slightly different again. Here are the instructions for Intellij 13:
click on the Project view or unhide it by clicking on the "1: Project" button on the left border of the window or by pressing Alt + 1
find your project or sub-module and click on it to highlight it, then press F4, or right click and choose "Open Module Settings" (on IntelliJ 14 it became F12)
click on the dependencies tab
Click the "+" button on the right and select "Jars or directories..."
Find your path and click OK
In the dialog with "Choose Categories of Selected File", choose Classes (even if it's properties), press OK and OK again
You can now run your application and it will have the selected path in the class path
It appears that IntelliJ 11 has changed the method, and the checked answer no longer works for me. In case anyone else arrives here via a search engine, here's how I solved it in IntelliJ 11:
Go to the Project Structure, click on Modules, and click on your
Module
Choose the "Dependencies" tab
Click the "+" button on the right-hand side and select "Jars or directories..."
Add the directory(ies) you want (note you can multi-select) and click OK
In the dialog that comes up, select "classes" and NOT "jar directory"
Make sure you're using that Module in your run target
Note that step 5 seems to be the key difference. If you select "jar directory" it will look exactly the same in the IDE but won't include the path at runtime. There appears to be no way to determine whether you've previously selected "classes" or "jar directory" after the fact.
You can try -Xbootclasspath/a:path option of java application launcher. By description it specifies "a colon-separated path of directires, JAR archives, and ZIP archives to append to the default bootstrap class path."
Set "VM options" like: "-cp $Classpath$;your_classpath"
I am using Idea 8.
in your module dependancies tab (in the project structure dialog). Add a "Module Library". There you can select a Jar Directory to add. Then make sure the run profile is using the Classpath and JDK of the correct module when it runs (this is in the run config dialog.
Simply check that the directory/package of the class is marked as "Sources Root". I believe the package should be application or execution in your case.
To do so, right click on the package, and select Mark Directory As->Sources Root.
You need not specify the classes folder. Intellij should be able to load it.
You will get this error if "Project Compiler output" is blank.
Just make sure that below value is set:
Project Settings -> Project -> Project Compiler output
to your projectDir/out folder
Open Settings
Under project Settings, select "project settings (1)"
On the left, select "modules"
Select the desired module
Select the "Sources" tab
In the tree structure, find the directory you want to add. Then either add as a source or test source.

Categories