NetBeans doesn't recognize ${project.organization} in license template - java

Can anybody reproduce the following?
In my NetBeans 7.2 project I've set the "project.license" property (in project.properties) to "apache20" so that NetBeans generates the appropriate license text in every new .java file. The license text (which is located in "license-apache20.txt") contains the following FreeMarker reference:
${project.organization!user}
When "project.organization" is not set it displays my user name as expected. Also, when I set a custom user name in the User.properties file it displays this user name instead. So far so good.
However, I want to set the "project.organization" property. But when I do this in the project.properties file NetBeans simply doesn't recognize it, displaying my user name instead.
When I remove "!user" from the FreeMarker reference it generates the text "Expression project.organization is undefined on line 4, column 59 in Templates/Licenses/license-apache20.txt." When I set the property in User.properties instead (silly place, but I did it for sake of analysis) I get the same behavior. Does anyone know what might be wrong or how to get NetBeans to find the "project.organization" property? Does anyone have the same behavior on his or her NetBeans?

In license-apache20.txt (or any other license template), change ${project.organization!user} to ${organization!user}
In NetBean menu, Tools ❯ Template, when you click the Setting button, a User.properties file is opened. Add organization=FooBar Inc there.
(This is not very ideal, but at least it allows to customize the organization.)

Related

Tried to change author name in Netbeans and now I can't commit to Github

Let me start of saying that I'm a beginner and don't know much about Github and Java. I'm also using Netbeans. Right now I'm doing the Helsinki MOOC Java Open Course that some of you might be familiar with. I could commit the code and upload to Github easily, but then I noticed that the Author name in Netbeans was different from my Github name and I tried to change this by changing the name in Git.properties file to the same name as on Github, and now I get errors everytime I try to upload new code to Github, even though I have tried reinstalling Netbeans and deleting the git.properties file. To make things easier for you, check my uploaded pictures of the errors I'm getting. How can I fix this?
Git push failed
Merge commit needed
Resolve conflicts
Resolve Conflicts2
It is an option in some java IDEs including eclipse and netbeans which automatically makes a document for your class ,interface etc.
These IDEs use a variable called user in the follow of #author property in class document.
Your problem starts when the user value equals to your current OS username that you login in it.
To prevent "netbeans" to write the OS username as default author name you can go to tools > templates.
after click on templates a dialog will be showed which include some folders like WEB,JAVA,JAVAFX etc.
In every folder we have some files like "Java class","Java Interface" etc which are your default shortcuts when you want to create a new item like an interface or a class , enum etc.
These files are your default templates for instance when you right click on a package > new > java class it make a java class in that package and its content is based on tools > templates > java > java class.
All you must do is to change every shortcut you want like java class or interface by open up tools > templates > java and click on java class or interface then click on open in editor button then search for somewhere like #author ${user} you must change the ${user} to your github username as the following example :
from :
/**
#author ${user}
*/
to :
/**
#author Swedishnovice
*/

Problem with IntelliJ -> Cannot create class with name "Main"

Title states my problem, i get this error message:
Cannot Create Class Unable to parse template "Class"
Error message:
Selected class file name 'Main.java' mapped to not java file type
'Files supported via TextMate bundles'
Anyone got any ideas on how I can solve this?
Please check the File Types. It looks like Main.java file name or extension was mapped to the wrong file type by accident (Files supported via TextMate bundles). Remove the invalid type mapping to fix the problem. The name/extension should be mapped to Java files instead (the default setting).
See if disabling TextMate bundles plug-in helps.
You do not need "Edit" button at all. Instead you need to use "-" (Minus) button in Registered Patterns area:
Select required file type in top list (Recognized File Types) -- do it for "Text files"
In bottom list (Registered Patterns) select undesired pattern -- "SomeFileName.java"
Click on "-" (Minus) button to remove pattern from the list
Repeat 1-2-3 for other undesired patterns
If desired, you can also do this manually by editing config file while IDE is closed. Because it's IDE-wide setting, it is not stored in .idea folder (which has project settinsg only) -- the file to look for is called filetypes.xml and shoudl be located in ~/Library/Preferences/IntelliJIdeaXX/options ( see http://devnet.jetbrains.net/docs/DOC-181 for other OS etc )

How to solve java file mapped to not java file type text

I wanted to add a java class to a project, but I did a mistake and added it as a text file. Then, I removed it and tried to add it again as a java class, but unfortunately it doesn't work anymore. And I get the following error:
Unable to parse template "Class" Error message: ABC.java mapped to not java file type text
As I searched, I faced some solutions like
this one but I can't find File Type under Editor or anything similar that I can change as suggested in the solution.
Any help would be appreciated.
PS: I am using IntelliJ 2018.3.4.
Thanks in advance,
Go on File->Settings and a dialog will open. In that dialog navigate on the left part to Editor/File Types and then you need to choose from the section Recognized File Types Java Class and remove from bottom section the problematic extension (note you have a small minus button on the right)
https://www.jetbrains.com/help/idea/creating-and-registering-file-types.html
This is a variant of Markov's answer that worked in my scenario.
Try going to File->Settings->Editor->File Types and to the Recognized File Types tab. Click the "Auto-detect file type by content" choice, and delete the name of the file you are trying to create from the "File Name Patterns" section by using the minus button.
Select required file type in top list (Recognized File Types) -- do it for "Text files"
In bottom list (Registered Patterns) select undesired pattern -- "SomeFileName.java"
Click on "-" (Minus) button to remove pattern from the list
Repeat 1-2-3 for other undesired patterns
If desired, you can also do this manually by editing config file while IDE is closed. Because it's IDE-wide setting, it is not stored in .idea folder (which has project settinsg only) -- the file to look for is called filetypes.xml and shoudl be located in ~/Library/Preferences/IntelliJIdeaXX/options ( see http://devnet.jetbrains.net/docs/DOC-181 for other OS etc )
Certainly inelegant, but you can simply copy the contents of the file to the clipboard (ctrl-c or similar), delete the file (maybe make a temporary backup somewhere outside the project), then in IntelliJ go to the desired package, right click, select new, select Java Class, name it correctly, and then you can paste in the contents of your file (ctrl-v or similar).

How to disable error highlighting in VS Code?

I need to disable error highlighting in Java files in VS Code. VS Code tries to check a Groovy file while thinking it is a Java file.
As you can see in the picture all imports after the first and the types after the first field are highlighted red (due to missing semicolons). However I do not want the error check for this Groovy file.
NOTE: I only have the plugins Clang, RedHat.Java, Markdown PDF, Sort Lines, and Uncrustify installed. Even if I disable all the red highlighting is visible.
open your preferences file and add this
"java.validate.enable": false
I didn't try it for java, but it works for typescript.
I found this:
"problems.decorations.enabled": false,
You should disable the linter, which is by default enable in VS Code.
To do so you can go to File-> Prefrences -> setting
I wouldn't think this is necessary but you might try:
"files.associations": {
".groovy": "groovy"
}
in your user settings, assuming your file extension is .groovy. If it is something else, just set it to "groovy" as well. When I create a .groovy file with your content or gibberish I get no error linting at all. What is your file extension and what does Vscode call it in the bottom right of the editor? You can click on that file type to change its file associations. See modifying Vscode file extensions.

Can I set up a keybind/hot key/macro to paste a line into Eclipse?

I know Eclipse has default keybindings (copy, paste, etc), and you can set keybinds for commands they've already decided on (Generate Setter/Getter, etc) but is it possible to set up a custom command?
For example, I can press Shift+F5 and it'll automatically type or paste "System.out.println();" for me.
In Eclipse Preferences, go to Java->Editor->Templates
Click on "new" to create a new template.
In your template, write in the "pattern" textarea the command you want to be pasted.
For example :
throw new IllegalArgumentException("");
And in the "name" textbox, write the word that matches to that command.
Then, in Eclipse, in your Java Editor, write that word + auto-completion. Eclipse will propose you,among others may be, your template.
The sysout command name is that template :
System.out.println(${word_selection}${});${cursor}

Categories

Resources