When I create a new Java file in NetBeans, I get auto documentation for #author. How can I setup NetBeans that is also documents the time and date of creation of the class?
I know NetBeans can do it as I get the time and date of creation in new CSS files by default.
You can change the template files in Netbeans. Go to Tools|Templates. From the available templates, find the one you want to change, let's say Java|Java Class, then select Open in Editor
Then goto to FaqTemplateVariables for list of available template variables. In your case, you're looking for ${date} and {$time}
Then you modify the template the way want, for example...
<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "${project.licensePath}">
<#if package?? && package != "">
package ${package};
</#if>
/**
*
* #author ${user}
* ${date} ${time}
*/
public class ${name} {
}
Then simple create a new "Java Class" - File|New File|Java|Class and it should then generate a file similar to this...
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package my.awesome.library;
/**
*
* #author noob
* 25/06/2017 3:19:39 PM
*/
public class Test {
}
Now, you'll probably have to go through a number of the other templates and update them, but that gives you a place to start
#MadProgrammer answered well. Just in case as an addition to this answer. U can optionally add properties in the User.properties file which is read by the various templates in the Tools -> Templated ->* configs. So if u want to add version to your Java classes. you can define the #version in the Java class template and then define the property in the User.properties file as in the following
In Your Java class template
....
/**
* ${date} ${time}
* ${version}
* ...other
*/
U can then set these properties in the User.properties file as
version=1.0.0
etc
Related
When executing I have error: cannot find symbol in the line MyCalcs.MtgeCalc(); in file Main.java
Why is it so???
in file Main.java I have:-
e/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.MyJava.002mavern;
public class Main {
public static void main(String[] args) {
MyCalcs.MtgeCalc();
}
}
and in file MyCalcs.java I have:-
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.MyJava.002mavern;
public class MyCalcs {
public MyCalcs() {
}
public static double MtgeCalc(){
System.out.println("mtgecalc");
return 10;
}
}
...just adding more text here to satisfy the post question data integrity checks but it seems a lot of text is needed here so i'll keep typing until I am able to post my question...
Have you tried changing the packing name? As user mentioned, package name cannot start with a number. Try com.MyJava, instead of com.MyJava.002mavern, and the code will compile and run.
UPDATE #2: Besides the incorrect package, it seems not all the Java files are compiled. Try javac *.java to compile both Java files. Also, see these 2 Java 8 references for more information on the javac and java commands:
javac: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html
java: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html
So I am learning to make a general template for java. So in Netbeans I went to the Tools menu and opened the Templates Manager and Opened the Java Class Template. This is what I did:
<#if package?? && package != "">
package ${package};
</#if>
/**
*
* Author: ${user}
* Created : ${time} ${date}
* Last Modified : ${lastUpdated}
*/
public class ${name} {
}
And the output is this:
package Maths;
/**
*
* Author: Emanuel Parkman
* Created : 3:40:29 AM May 22, 2014
* Last Modified : Expression lastUpdated is undefined on line 9, column 22 in Templates/Classes/Class.java.
*/
public class NewClass {
}
But when I look at the Freemarker Website : http://freemarker.org/docs/ref_builtins_date.html#ref_builtin_date_datetype
${lastUpdated}
Is used as one of the built-ins... I just want my comments to show when the java file was last saved. Is that possible? and if so, how?
You misunderstand the manual there. lastUpdated is not a built-in variable in FreeMarker. All the variables that you are using, like name, package, time, are provided by NetBeans. After all, FreeMarker is not specialized on generating source code (in fact, it's much more often used for generating Web pages). So check what variables are available in the NetBean documentation. Or, maybe try to list the available variables, like described here: does freemarker support show all variable in data-model?
Not sure if it will be Eclipse or Eclipse-plugin-dev answer.
In open-source Nodeclipse project plugin.xml defines that .coffee file can be launched as coffee, coffee --compile or Node with monitor (There are 3 defined LaunchShortcuts).
First time it work fine, but then consequent launches only repeat previous LaunchType. I have found that deleting saved LaunchConfiguration (from Run -> Run Configurations) will let it run again (and then only as this type again)
The code in question is LaunchShortcut (see snippet below), however there is no any if checking, so this behavior should be deeper in Eclipse org.eclipse.debug module.
How can saved LaunchConfiguration override LaunchType ?
/**
* Launch an file,using the file information, which means using default
* launch configurations.
*
* #param file
* #param mode
*/
private void launchFile(IFile file, String mode) throws CoreException {
// check for an existing launch config for the file
String path = file.getFullPath().toString();
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(Constants.LAUNCH_CONFIGURATION_TYPE_ID);
ILaunchConfiguration configuration = createLaunchConfiguration(type, path, file);
DebugUITools.launch(configuration, mode);
// then execution goes in LaunchConfigurationDelegate.java launch() method
}
/**
* Create a new configuration and set useful data.
*
* #param type
* #param path
* #param file
* #return
* #throws CoreException
*/
private ILaunchConfiguration createLaunchConfiguration(ILaunchConfigurationType type, String path, IFile file) throws CoreException {
String configname = file.getFullPath().toString().replace('/', '-');
if(configname.startsWith("-")) {
configname = configname.substring(1);
}
ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(type);
for(ILaunchConfiguration config : configs) {
if(configname.equals(config.getName())) {
return config;
}
}
// create a new configuration for the file
ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, configname);
workingCopy.setAttribute(Constants.KEY_FILE_PATH, path);
setMoreAttributes(workingCopy);
return workingCopy.doSave();
}
protected void setMoreAttributes(ILaunchConfigurationWorkingCopy workingCopy) {
// stub for extension
}
Help! The code snippet is maybe not enough to answer the question, but references files and everything is in Github repository. The question was raised, because I am not sure if it is possible at all to have many Run Configuration for the same file. Then code snippets doesn't matter at all.
Update: Looking after a while at plugin.xml defines that .coffee file can be launched , I noticed that I am actually using the same <configurationType
id= "org.nodeclipse.debug.launch.LaunchConfigurationType" > in all 5 cases. However adding unique LaunchConfigurationType id for every launch makes no difference.
You can create the launch configuration with this:
Creating a Java application launch configuration
Launch groups can also be setle with this help:
Launch Group
Until here Im pretty sure you have knowledge about, so lets keep moving; You can have different launch configuration for the same file, thats handled with the launch group tool, what I dont get is if you want those different configuration for the same environment or not.
Also here Launch Configuration Types and here Adding launchers to the platform you cand find information about the struct of the launch type file
To finish here Interface ILaunchConfigurationTabGroup is the interface of the launch type tab group;
My Suggestion in codelines:
<extension point="org.eclipse.debug.ui.launchConfigurationTabGroups">
<launchConfigurationTabGroup
<"launchConfigurationType1"
<"/launchConfigurationType1">
<"launchConfigurationType2"
<"/launchConfigurationType2">
//and so on...
</launchConfigurationTabGroup>
</extension>
I have authored a mojo that generates code and sticks it under {root}/target/generated-sources/foo. When I execute:
mvn clean install
I get errors indicating that the generated sources are not being included in the build path (the generated files are there, but not being picked up in the compile phase). I understand from this answer that I need to dynamically add {root}/target/generated-sources/foo as a source directory for the POM. Problem is, I haven't been able to track down any information on how to do this.
As a backup plan, I intend to use the Build Helper Maven Plugin, but I was hoping to do this automatically in my mojo if possible.
I prefer to add this to my Mojo:
/**
* The current project representation.
* #parameter expression="${project}"
* #required
* #readonly
*/
private MavenProject project;
/**
* Directory wherein generated source will be put; main, test, site, ... will be added implictly.
* #parameter expression="${outputDir}" default-value="${project.build.directory}/src-generated"
* #required
*/
private File outputDir;
Obviously you can change the default-value to match your own pattern.
And then in the execute() method:
if (!settings.isInteractiveMode()) {
LOG.info("Adding " + outputDir.getAbsolutePath() + " to compile source root");
}
project.addCompileSourceRoot(outputDir.getAbsolutePath());
In JetBrains IntelliJ IDEA, I would like to edit comment which is like
/**
* Created by IntelliJ IDEA.<br/>
* User: ${USER}<br/>
* Date: ${DATE}<br/>
* Time: ${TIME}<br/>
* To change this template use File | Settings | File Templates.
*/
and generate comment for a type like
public class MyUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter
or a function like
protected void checkUsbKeyID(UserObj user,String usbKeyID)
Type comments you can edit in menu File -> Settings -> File Templates.
Then you look to tab Includes and edit entry File Header
Method comments isn't possible to edit, I think.
To change the specific template for Classes, edit the Class template.
Example menu locations (should be broadly similar on other platforms/versions)
IntelliJ 2016, Mac
Preferences > Editor > File and Code Templates > Files tab > Class item
IntelliJ 14.x, Mac
Preferences > Editor > File and Code Templates > Templates tab > Class item
It looks like this
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public class ${NAME} {
}
The link to the sub-template which generates the comments is #parse("File Header.java") on the second line.
You can remove that and put a custom comment template for Classes inline here.
or
You can edit the File Header template under the includes tab, which is also used by other things, and edit that