I have duplicated and edited the templates "new java class" and "new java main class" in Apache Netbeans 11. My purpose is to have the option to create a new project with my templates. Currently Netbeans creates the project with its own default classes.
I tried right-click -> properties etc, I was unable to reach what I want.
Related
When creating new Java classes, my copy of Eclipse doesn't put them in a package. It gives me a warning about not putting the class in the default package, but it doesn't give me any other options.
I've seen other people use Eclipse, and their copy of Eclipse defaults them to a package named after the project they just created. I can't figure out why my copy of Eclipse is acting differently.
Here's what I'm doing:
File -> New -> Java Project
Name the project "quickTest". Leave everything else the same ("use default location" checked, JRE as JavaSE-16, Project Layout as "Create separate folders", Working sets unchecked, "Create module-info.java" checked). Press Finish.
Hit "Create" on the "Create module-info.java" popup, using the default module name "quickTest"
File -> New -> Class
In the "New Java Class" dialog, the package is blank and there's a warning about "The use of the default package is discouraged". If I hit "Browse...", "default package" is the only option.
What am I doing wrong? How can I get Eclipse to auto-create a "quicktest" package when it creates the project, in the way I've seen it do for other people?
Yes, I know I could manually create the package afterwards, but I'd rather not have to do an extra step.
This is Eclipse 2021-06 (4.20.0)
A new project does not have any packages defined. For the very first class you create in a project just type the package you want directly in the "Package" field of the New Class dialog. Eclipse will create the package folders and create the class in the package.
For subsequent classes you create the package will be filled in.
You can always type a package name in the Package field if you want to create a new package.
So, the owner of the other computer showed me the trick. Apparently, it matters how you start the new class wizard.
If you create a new class by right-clicking on the project in the Package Explorer, it will fill in the package name automatically. But if you create the new class from the File menu, it doesn't.
So, this works:
File -> New -> Project
Name the project "quickTest". Leave everything else the same (see above). Press Finish.
Hit "Create" on the "Create module-info.java" popup, using the default module name "quickTest"
Right click on the project name in Package Explorer -> New -> Class
The package name will be filled in with "quickTest".
(Apparently, this only works if the project name starts with a lower-case letter.)
Honestly, it feels like a bug that it works one way and not the other, but that's how you avoid needing to manually add a new package.
Is it possible to do so in Netbeans, or do I just have to manually change the package name each time I create a new project?
To create a project MyJavaProject with the main class not in a myjavaproject package, to this:
Click New Project...
Choose a Project Type
Change the Package
Demonstrated below as the selected text
Click Finish
This allows for one to create a new project with a different package name without having to manually change it after the project is created. Also note that this is NetBeans 8.0.2.
I am using Eclipse Mars.2 (4.5.2) and Gradle IDE 3.7.3.201602250836-RELEASE. How can I add a custom "sample project" to the "New Gradle Project" wizard?
It's annoying to have to do the same cleanup steps to remove the sample stuff each time I create a new project. I'd really like to start off with a defaults configured to my environment and preferences.
This is the wizard I'm talking about. It's accessed via New Project -> Other -> Gradle (STS) -> Gradle (STS) Project.
I
Gradle doesn't really have an equivalent of maven-archetypes. The sample projects you're seeing in that drop down box are provided by the STS eclipse extension itself. You're out of luck if you're trying to add your own templates to the dropdown box, unless if you modify the code of the eclipse plugin. You can find the source code here:
https://github.com/spring-projects/eclipse-integration-gradle/blob/a1d5554b1c0b0faf8a48b7585ac5371aa9a59793/org.springsource.ide.eclipse.gradle.core/src/org/springsource/ide/eclipse/gradle/core/samples/SampleProjectRegistry.java
The comment banner in there says:
Instance of this class is responsible for knowing all the sample projects that can be used by
the New Gradle Project Wizard.
For now the registry is not extensible. The samples are more or less hard-code in here. In the future
we might create an extension point to register the samples from external plugins.
They're pulling a few samples from the gradle-ver-all.zip distribution here
I'm working with Eclipse and am able to create projects, but I want to start building my own libraries.
How can I link to class/library files from outside the Eclipse environment?
lee
(Assuming you are developing Java projects with Eclipse).
Right click on your project name to display bring up context menu
Select Project properties... to display properties panel
Select Java Build Path
Select the Libraries tab
You can now add a external library in a variety of ways: A JAR that belongs to another Eclipse project, an external JAR, a directory, etc.
I am using Netbeans 7.0.1 with a web project that I have imported from existing sources. I have added the JUnit library to my project. In Netbeans tutorials online for version < 7 it says to create a JUnit test for a given existing class by righ-clicking on the source file in the project, select the menu "Tools" and then there should be an option to create a JUnit test. However this option does not appear for me. There seem to bean old bug report/request for functionality, describing this but it does not seem to have been resolved as it is mentioned as late as 2011-05-09 on the Netbeans bugzilla list (link Related on bugzilla). On the bugzilla it is suggested to explicitly create the folder /test/unit/src in the project, but still after this when I try to create JUnit test for an existing class from rightclick project -> new -> other -> JUnit, I get "no tests root folder was found in the selected project" (I tried changing the foldername to tests as well). Can I explicitly set this location in some configuration file and is there any way of getting the expected functionality allowing me to simply righclick a source file and select "JUnit test" to create a JUnit stub for the selected class ?
If you right click on the project and pick "Properties" you should see "Sources" on the left. Select that and then click "Add Folder..." under the "Test Package Folders" section. This will add a new test directory. If you have an existing one, delete it first (just make sure the test sources are saved somewhere else) and then add the new one.
If you right click on your project and add new Unit Tests-> JUnit Test it will automatically create the path for you.
if src/main/java is missing, netbeans 8 does not let you create test case in src/test/java using the wizard
looks like a bug, still valid in 2015
What kind of project you've made has a large effect on whether there's a test root already or no. In Netbeans 7.1.1, a "POM Project" doesn't create a test root directory as a part of the project build process. However, making a Java Application did make a test root by default.
I tried the directions offered by mamboking and I wasn't able to change the directories in the Sources section of the project properties. Making a new project of type "Java Application" make the correct test root.