导航:首页 > 知识产权 > java如何将自己的代码自动添加版权信息

java如何将自己的代码自动添加版权信息

发布时间:2021-05-08 02:48:46

⑴ java代码如何快速添加作者描述的注释最好能有详细的图解

Window -->Preferences->Java->Editor->Templates ,
在这里new一个自己的插入注释的快捷方式名称,具体设置如下:
Name处输入 remark (任意你喜欢的名称)
context处选 java 后边勾选Automatically insert复选框
Description 这里可以任意输入描述
Pattern :(自定义格式)
/**
* @author ${user}
* @date : ${date} ${time}
*/
到这里全部设置完毕,下面 OK,找个java类,找个空白处测试一下, 输入remark(前面写的那个Name名称),
再alt+/ 应该按一下就能看到刚才的Description的内容。

⑵ 如何给JAVA源代码文件统一地添加licence信息头

下面就直接上代码吧!当然懂得就跳过。

/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding right ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.apdplat.platform.util;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/**
* 给JAVA源代码文件统一地添加licence信息头
* 检查文件package、import、类级别注释、是否有public class
* 用到了Java7的新特性,强大
* @author ysc
*/
public class AddLicenceForJavaFile {
private static int count = 0;
private static List<String> fail = new ArrayList<>();
private static List<String> wrong = new ArrayList<>();
public static void main(String[] args) {
String licence="/**\n" +
" * Licensed to the Apache Software Foundation (ASF) under one or more\n" +
" * contributor license agreements. See the NOTICE file distributed with\n" +
" * this work for additional information regarding right ownership.\n" +
" * The ASF licenses this file to You under the Apache License, Version 2.0\n" +
" * (the \"License\"); you may not use this file except in compliance with\n" +
" * the License. You may obtain a of the License at\n" +
" *\n" +
" * http://www.apache.org/licenses/LICENSE-2.0\n" +
" *\n" +
" * Unless required by applicable law or agreed to in writing, software\n" +
" * distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
" * See the License for the specific language governing permissions and\n" +
" * limitations under the License.\n" +
" */";
addLicenceForJavaFile(new File("D:\\Workspaces\\NetBeansProjects\\APDPlat"),licence);
System.out.println("为 "+count+" 个Java源代码文件添加licence信息头");
if(fail.size()>0){
System.out.println("处理失败个数 "+fail.size());
for(String f : fail){
System.out.println(" "+f);
}
}
if(wrong.size()>0){
System.out.println("JAVA源代码错误个数 "+wrong.size());
for(String w : wrong){
System.out.println(" "+w);
}
}
}
/**
* 给JAVA源代码文件统一地添加licence信息头
* @param path 源码所处的根目录
* @param licence 许可证信息(在netbeans中复制一段文本粘贴到变量的双引号内,IDE自动格式化,相当赞)
*/
private static void addLicenceForJavaFile(File path, String licence) {
if (path != null && path.exists()) {
//处理文件夹
if (path.isDirectory()) {
String[] children = path.list();
for (int i = 0; i < children.length; i++) {
File child = new File(path.getPath() + System.getProperty("file.separator") + children[i]);
//递归处理
addLicenceForJavaFile(child, licence);
}
} else {
//处理java文件
if (path.getName()。toLowerCase()。endsWith(".java")) {
System.out.println(path.getAbsolutePath());
count++;
try {
byte[] content;
try (RandomAccessFile f = new RandomAccessFile(path, "rw")) {
content = new byte[ (int) f.length()];
f.readFully(content);
}
String text = new String(content);
text = text.trim();
while (text.startsWith("/n")) {
text = text.substring(1);
}
//如果已经有同样的licence,则忽略
int pos = text.indexOf(licence);
if(pos!=-1){
return;
}
//有package声明的,保留package以后的内容
if (text.indexOf("package") != -1) {
text = text.substring(text.indexOf("package"));
}
//没有package声明的,有import声明的,保留import以后的内容
else if (text.indexOf("package") == -1 && text.indexOf("import") != -1) {
text = text.substring(text.indexOf("import"));
}
//没有package声明也没有import声明的,有类级别注释的,则保留类级别注释以后的内容
else if (text.indexOf("package") == -1 && text.indexOf("import") == -1 && text.indexOf("/**") != -1 && text.indexOf("public class") != -1 && text.indexOf("/**")<text.indexOf("public class") ) {
text = text.substring(text.indexOf("/**"));
}
//没有package声明也没有import声明的,也没有类级别注释的则保留public class以后的内容
else if (text.indexOf("package") == -1 && text.indexOf("import") == -1 && text.indexOf("public class") != -1 && ( text.indexOf("/**")>text.indexOf("public class") || text.indexOf("/**")==-1 )) {
text = text.substring(text.indexOf("public class"));
}else{
wrong.add(path.getAbsolutePath());
return;
}
try (FileWriter writer = new FileWriter(path)) {
writer.write(licence);
writer.write("\n\n");
writer.write(text);
}
}
catch (Exception ex) {
fail.add(path.getAbsolutePath());
}
}
}
}
}
}

⑶ vs 如何将自己的代码自动添加版权信息

把那些在Common7\IDE\ItemTemplates\CSharp\2052下面的压缩复文件复制到制C:\Documents and Settings\用户名\My Documents\Visual Studio 2005\Templates\ItemTemplates\Visual C#(或者是web版)中去,再对其进行修改.当我们再添加新项的时候,那些模板就出现在"我的模板"下面了. 如果在另外一台机器上写代码,只需要把这些模板放到用户自己的文件夹就可以了,也很方便携带.

⑷ 如何在VS中自动添加自定义版权信息

找到 安装目复录:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCache\Web\CSharp
\2052\Class.zip
打开制Class.zip中的 Class.cs文件 就会看到如下所示代码:
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Web;
/// <summary>
///$safeitemrootname$ 的摘要说明
/// </summary>
public class $safeitemrootname$
{
public $safeitemrootname$()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
}
然后只要在其顶部加入版权信息代码就可以了

⑸ 如何在自己的代码中声明版权

菜单工程来-工程1(改成自己的)属性源-生成-修改对应的内容。 不过网上的vb6企业版对应的是乱码! 建议用记事本直接更改vbp文件内容。 回答者: ynzsvt - 经理 四级 5-2 11:03工具栏-工程-属性-生成 就可以看到并修改版权信息

⑹ 当别人复制你的文章时怎么自动在最后加上版权信息

这个可以通过JS来实现。举例:
把代码插入到HTML文件中
<body>
<script type="text/javascript">
document.body.on = function () {
setTimeout( function () {
var text = clipboardData.getData("text");
if (text) {
text = text + "\r\n本文来自:XX网(具体网址)具体网址:"+location.href; clipboardData.setData("text", text);
}
}, 100 )
}
</script>
</body>
即可实现。

⑺ 如何将自己的代码自动添加版权信息的及其扩展

找到 安装目录:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCache\Web\CSharp \2052\Class.zip 打开Class.zip中的 Class.cs文件 就会看到如下所示回代答码: using System; using System.Collections.Generic;

⑻ 代码注释中怎样添加版权信息,版权信息都包含什么内容

代码注释中添加版权信息主要包括以下几项:

1、文件名

2、文件功能描

3、author(作者)

4、时间版

5、创建标识权

6、修改标识

7、修改描述。

(8)java如何将自己的代码自动添加版权信息扩展阅读:

法律规定:

根据著作权法的规定,版权所有人可以根据法律在法律规定的年限内对作品享有独占权。一般而言,其他人需要使用作品,应当事先取得版权所有人的许可,并向其支付报酬。

但是著作权法也规定了若干情形,在法律规定的使用方式下,该种使用无需取得版权所有人的许可,或者无需向其支付报酬。版权的期限,简单来说,对个人而言,是死后五十年,署名权等精神权利期限无限制;对单位和法人而言,使作品首次发表后五十年。

外国人或者外国在中国国内首次出版的,受我国法律保护,其他的根据国际条约确定,多数重要国家已经和中国一起参加了共同的国际条约,在这些缔约国境内产生的作品同样受到我国著作权法的保护。

⑼ 如何设置 Eclipse 创建类时自动添加 自动生成的 作者以及日期注释

使用Eclipse 编写Java代码时,自动生成的注释信息都是按照预先设置好的格式
生成的。
修改作者、日期注释格式:
打开Windows->Preferences->Java->Code Style->Code Templates,
点击右边窗口中的Comments,可以看到有很多选项,
我们便可对此注释信息模板进行编辑。
如我们希望在一个Java文件的开头设置作者信息、日期信息。
选择Types,点击Edit,将
/**
* @author ${user}
* ${tags}
*/
将${user}删除,改成你希望显示的名字
将${tags}删除,
点击Insert Variable,选择Date,这样就会自动生成日期信息。
在你需要添加注释的地方点击Sources->Ganarate Element Comment,
或者使用快捷键 Alt+Shift+J ,则 eclipse 自动在该类前面添加注释。

阅读全文

与java如何将自己的代码自动添加版权信息相关的资料

热点内容
武汉疫情投诉 浏览:149
知识产权合作开发协议doc 浏览:932
广州加里知识产权代理有限公司 浏览:65
企业知识产权部门管理办法 浏览:455
消费315投诉 浏览:981
马鞍山钢城医院 浏览:793
冯超知识产权 浏览:384
介绍小发明英语作文 浏览:442
版权使用权协议 浏览:1000
2018年基本公共卫生服务考核表 浏览:884
马鞍山候车亭 浏览:329
学校矛盾纠纷排查领导小组 浏览:709
张江管委会知识产权合作协议 浏览:635
关于开展公共卫生服务项目相关项目督导的函 浏览:941
闺蜜证书高清 浏览:11
转让房转让合同协议 浏览:329
矛盾纠纷排查调处工作协调交账会议纪要 浏览:877
云南基金从业资格证书查询 浏览:313
新知识的摇篮创造力 浏览:187
股转转让协议 浏览:676