My instructor had us all install the Maven add-on for programming in Java. Now, any time I make a new Java program, it is not recognized by Eclipse. By this I mean it redirects to another program. Also, when looking in "Run Configurations", under "Java Applications", any new programs I make don't show up there. However, all programs should show up here.
Example:
Say I have a program named "Test" that I made before installing Maven. Now say I made a program "Test2" after installing Maven. When running Test, it works fine. But when running Test2, it runs Test. Other than it showing in the directory on the left, Eclipse makes no indication that Test2 actually exists. That is my issue.
My Question:
How do I completely remove Maven from my system? I don't want to use System Restore.
What I've Tried:
I have removed the Environment Variable "M3 HOME" and removed it from the "Path" variable. The issue is still there, however.
I have a Windows 10 Lenovo Y50-70 Gaming Laptop (64 bit) with 4K resolution. I am using Eclipse Luna.
After messing around a bit, I figured out the answer.
Right click any "src" folder, and click something along the lines of "Exclude Maven Artifact" under the "Maven" option. This removed it from Eclipse, and I can now make new programs and run them again.
Hope this helps whoever has my issue!
Related
I am a java beginner, the first java IDE I downloaded was Visual Studio Code, it was very easy to use and everything is auto configured. But it kind overheats my laptop all the time, so I want to try IDEA, so far it's a very good experience, except when I open a java file and tried to run it in IDEA, it always pops out this run configuration window and I don't understand how to configure it. In visual Studio Code I can open any java file any time and run without any issues, but now I have to go through creating projects every time. Is there any solution for this?
From how the file icon looks:
your file is not recognized as the part of the sources of your project. Check the project settings to ensure that source directories are correctly set.
I'd also recommend you to look up and follow the conventions for the directory structure of java projects.
Once you've fixed the problem with sources, you'll see "run" icon next to your class, main method, or when you're right clicking the file.
Command-line
To run a single file, there is no need for an IDE.
In Java 11 and later, the java tool at the command-line can both compile and execute a single-file Java class. See JEP 330: Launch Single-File Source-Code Programs.
If your class named HelloWorld were in a file named HelloWorld.java, on a console type:
java HelloWorld.java
To be clear: The java command-line tool really only executes Java apps, while the javac command-line tool compiles Java source code. As a convenience, the java tool was enhanced to effectively call javac on your behalf for a single-file.
JShell
If you just want to run a few lines of Java, try JShell, the REPL tool bundled with Java 9 and later.
See:
Java Shell User’s Guide by Oracle
JEP 222: jshell: The Java Shell (Read-Eval-Print Loop)
Search to learn more and find tutorials.
BlueJ
Using an IDE such as IntelliJ, NetBeans, or Eclipse can be a daunting task for the new student of Java. Those IDEs are heavy-duty tools designed for professional programmers.
I recommend using an IDE designed for beginners. BlueJ comes to mind, designed specifically for educational purposes. BlueJ makes getting started with Java easier.
If you insist on using IntelliJ, read on.
If using IntelliJ, define a project
IntelliJ is not designed to work with single files. IntelliJ expects you to work within a project.
I strongly recommend learning the basics of Maven to create and drive your new project. By defining your project in Maven, the configuration is independent of any one IDE. You can move your project between major IDEs such as IntelliJ, NetBeans, and Eclipse.
Maven is also very useful for downloading needed libraries ("dependencies") that you may want to leverage in your work. And Maven is good at packaging your Java app as a JAR (or WAR or EAR).
In IntelliJ, choose "New Project". In the New Project window, click the Maven item on left. Check the Create from archetype box. Scroll the list to find item for org.apache.maven.archetypes:maven-archetype-quickstart. Under that, choose the "RELEASE" item. Click Next button.
In Name field, enter something like MyFirstProject. Click Next button.
On the Maven settings page, just click Finish.
Wait a moment for IntelliJ to download some stuff and configure your project. Eventually you should see a BUILD SUCCESS message in the Run pane.
You will also see a pom.xml file displayed. The POM contains your settings for Maven to run your project, in XML format.
Change the <maven.compiler.source> and <maven.compiler.target> elements to the version of Java you are using. The current version is Java 17.
After editing the pom.xml, look for a little floating windoid with a tiny Maven icon. Click the icon to have Maven process your changed POM. Wait a moment.
In the Project pane, navigate to the App file. There you see code to print “Hello World!”. Let's run that code now. Click the green triangle button on the left, in the gutter, next to the main method line. A pop-up menu appears offering a Run item. Choose that item to run the app immediately.
Down in the Run pane, you should see the results, the Hello World! text.
At this point you can add your single file to the org.example package seen in the Project pane.
By the way, you can change that package name by context-clicking and choosing Refactor > Rename….
Later, learn to use the Run/debug configurations feature of IntelliJ.
Know that you need not create a new project for each time you want to do a little experiment. Create one project for such experiments. Keep adding new .java class files for each experiment. Delete old class files you no longer need.
Eventually, I suggest updating the versions of various items in your POM. The QuickStart archetype is not configured for the latest versions (for reasons I cannot fathom).
And when you learn about unit testing, replace JUnit 4 in the POM with JUnit Jupiter (Aggregator) to use JUnit 5. One of the benefits of using Maven is that you can easily switch out dependencies such as going from JUnit 4 to JUnit 5.
The IDE needs to know what's called the entry point of the program, i.e. where to start running your code. That's what the "Edit Configuration" window is wanting you to do.
If your file "Lab3.java" is in a package, make sure to fully specify that in the field you have in red. Otherwise without knowing how your project is structured (as the other answer alludes to), it's difficult to pinpoint what we're missing here.
When you create your IntelliJ project, add a directory /src right at the root of your project. Right click on that folder and tell IntelliJ that you wish to mark it as a source root. The directory should turn blue in color.
Put your packages under /src. IntelliJ will know that those are Java files.
When you want to run a class with a main method, choose Run->Edit Configurations. Tell IntelliJ that you want to add an Application. It should prompt you with the classes that have main methods in them. You'll have no trouble running them.
Use Maven or Graddle. Make sure the project is configured with the build tool enabled and integrated, it will do basic things automatically. If you are not sure, please create a new project and add your files in. Steps:
Open the IDE
New Project
Choose from the left side bar "Maven" or "Graddle"
Give it a name and the location in your machine.
Click Finish
Now you have the project ready. You need the appropriate method to run in java. A main class. In IntelliJ you can just type "main" and the auto-complete will add it for you, make sure you inside the curly brackets of the class {}. More info about the main class. You seem to have this nailed down.
Lastly make sure you have a JDK installed in the IDE. I am pretty sure this is your issue here, make sure to use one of the option IntelliJ provides. A full guide from the developers is here and should satisfy your needs. I would suggest OpenJDK for a beginner, because that served me well at the beginning, at the end of the day its your choice.
I'm building a simple calculator app from a tutorial/class on Pluralsight (Java Fundamentals class), which starts with a Main.java file, and adds a class file later, MathEquation.java.
I created a Git repo to track my progress, and uploaded to Github: JavaFundamentalsClass. I used GitIgnore.IO to find a Java IntelliJ .gitignore file, and everything seemed to be working fine on the original PC I was using.
However, after switching over to a different PC, with a fresh install of IDEA, I cloned down the repo from Github, and found that the project would not build and/or run. I get this error:
"C:\Program Files\RedHat\java-1.8.0-openjdk-1.8.0.191-1\bin\java.exe" -Dfile.encoding=windows-1252 -jar ""
Error: Unable to access jarfile
Process finished with exit code 1
I suspect that there is something in the .gitigore file that is keeping some of the project, dependency, or build information from being saved in the repo that keeps IDEA from having all the info it needs to build and run the Main.java correctly.
Can anyone help? You should be able to download the project from the repo linked above in it's currently broken state, including the .gitignore file.
Additional Info
I wiped my repo clean and recloned and I forgot, originally it doesn't even give me the run button (it is grayed out). I had to do a procedure with "Add Configuration" from a search I did for that to show up to get the error above.
Also, I did install java from the OpenJDK, rather than oracle. I figured with Oracle cutting off commercial development maybe start the switch now as I'm learning, but maybe that's the issue (normal Java on my other PC).
It's working, but...
First thing - Intellij needs to know where Java is. It appears that if the SDK/JDK is not installed prior to Intellij, you will need to tell it where Java is after installing. Or if you use OpenJDK instead of Oracle Java SDK. You can do that at View/Open Library Settings, under Platform Settings / SDKs (select the JDK home path).
Then, after setting up Java, I am able to get everything working in Intellij IDEA if I find the Main.java file, right-click, and choose "Run main.main()". This runs the program okay, and also creates a Main configuration in the Run/Debug configuration area, and finally the "Run" button becomes available.
So I can get it working, but if I wipe all the files and clone it fresh from the remote repo, I have to go through running the Main.java file directly again to recreate the configuration.
So, this still doesn't answer my original question. Why doesn't this configuration get saved in the repo? What file is this information saved in? Is there something in the .gitignore file that is keeping this information from being saved to the repo?
Look like you have a different java version on your second machine.
First of all, check your java version
Update the configuration of your project, right now it pointing to java 1.8
https://github.com/LightCC/JavaFundamentalsClass/blob/master/.idea/misc.xml
I think it might be because of java not installed on the other PC you were trying. If it is installed just check whether the path mentioned has java executable file.
The first part is ensuring Java is setup, and that Intellij IDEA knows where Java is, per the other answers, comments, and addendums to the question.
The second part is setting up the run/debug configuration, per the "It's working but.." section of the question. This can be created automatically by right-clicking the file that has the main class to be run (usually Main()...), and selecting the "Run Main.main()" option (replacing Main and main() with the file and function which needs to be run)
The final piece is that to get the run/debug configurations to save to the repo, you either need to:
Share the workspace.xml file (i.e. make sure this is not in the .gitignore file). However, there is a lot of user-specific stuff in that file, so it should normally be excluded from the repo.
Or, edit the configuration and checkmark the "Share" box in the upper right-hand corner (just right of the "Name" field). This will put the configuration into a separate folder inside the .idea folder, which should not be excluded from the repo by .gitignore.
Pretty new to programming in general and my IDE in specific, and need a bit of help.
Relevant Info:
OS: Windows 7
IDE: Netbeans 8.2
Language: Java
Build: 1.8.0_152-b16
I tried to refactor a class name in a project because it had the same name as a library, but you some reason Netbeans wouldn't let me. In my infinite wisdom, I went to the src folder and re-named the file by hand.
Ever since then, I can no longer run ANY projects in Netbeans. This includes other projects that I did not touch the class names of. The projects will still build, but get stuck loading the run infinitely and never showing the output. Happy to supply any additional info that's required.
Edit: I've also already tried clearing Netbean's cache, that didn't work.
Sooooo... turns out my output box was just hidden and I thought the run wasn't working because all the programs I tested it with asked for user input before completing. My bad on the newbie mistake.
I am maintaining a java program that is not mine. I used eclipse and I could build the program with Ant. I don't know very much about Ant. Everything was installed fine on my eclipse IDE and the build worked perfect till today. I didn't change anything, so I don't know why it doesn't work anymore.
When I look at the external Tools Configurations,I see that the targets are missing. I have the message "No targets could be determined for the build file". Previously I could select some targets. Does someone know how it come that the targets disappeared?
I fixed it by switching the eclipse workspace. I went to menu File->Switch Workspace->Other, and then I have selected the same workspace I was working with. Eclipse restarted and the error wasn't there anymore.
This helped for me:
remove the build file from Ant view and add it again.
I installed Netbeans on OSX Mountain Lion running JDK 7. Everything was working fine. Then my machine for no reason crashed. After this I could no longer open Netbeans anymore.
If I try to start Netbeans from the commandline:
/Applications/NetBeans/NetBeans 7.2.app/Contents/MacOS/netbeans
Then it works fine. From there I can select Netbeans > About and confirm that my userdir and cachedir is:
User directory: /Users/<user>/Library/Application Support/NetBeans/7.2
Cache directory: /Users/<user>/Library/Caches/NetBeans/7.2
So, I deleted these directories and tried again, but alas, I can only start netbeans via the commandline.
Ideas appreciated...
Sounds to me like this is not a NetBeans problem at all, rather a problem with the bundle, such that OS X is not launching the app as it should.
To verify, I'd try opening NetBeans through Finder from the command line:
open -a "NetBeans 7.2.app"
This command will ask the system launcher to open the application as if you had clicked on the icon. In your case, it probably won't open. If this is true, then you know it's not something in your terminal environment that's allowing NetBeans to launch.
The next step that I would take would be to look at the package contents: examine /Applications/NetBeans/NetBeans 7.2.app/Contents/Info.plist for anything that seems amiss - this file is the information store that OS X looks for to see how to launch the package, what its icon is, etc... - in particular, I think you should look at the CFBundleExecutable value to see what command is used to launch the app. If it's not netbeans, you've found a big hint on what might be amiss: bundles are set up so that launchers should run bundle_dir.app/Contents/{platform}/{CFBundleExecutable_value}. Looking at CFBundleExecutable should show you if there's some other script used to launch the app than just running netbeans.
From this point, you'll have to do more digging, but hopefully this is enough information for you to get started tracking down how apps are launched from the OS X launcher. For more info and a better reference, check out this link, which is Apple's documentation for keys in Info.plist.
Finally, you should note that the launch information for all apps are heavily cached; I've heard that if you make a change to Info.plist, you have to rename the app bundle and name it back to have the changes picked up by the launcher.
Good luck!
Here's an idea: use Eclipse >=)
..but seriously, something got corrupted in Netbeans' metadata/cache data files. You cleared a couple of them but there may be others elsewhere.
Try comparing the launch command in your shortcut to what you're typing in the console. Are they the same?
To find the root cause, I would check the NetBeans logs, as detailed here
/Users/yourname/Library/Application Support/NetBeans/7.2/var/log/messages.log
And if that doesn't help, I'd archive your project(s) and put a clean install of NetBeans on your machine, and then import the archived project(s) back into NetBeans.