简体   繁体   中英

Java custom library export and import with eclipse

I want to create my own library with some custom methods that will return different strings for encryption and decryption. I know how to export a specific class with eclipse, but after I import the jar file I don't know how to call those methods.

package com.chriss.cipher;

public class MyLibrary {
    private static final String MSG_1 = "<My awesome 1 MESSAGE>";

    public String generateString(int val){
        return val+" --> "+MSG_1;
    }

    protected String testingString(int value){
        return value + " <this is awesome> !";
    }

    private String testMyString(int value){
        return "---> " + value;
    }
}

A custom made library it should be abstract?

Why people said that my methods should be protected and don't expose anything that I wouldn't want in public. Is this some security risk? Security from what?

To use the library jar, you would need to import the exported jar file into the project or rather the classpath (to be precise).

import the class into your java file and invoke the method.

For details on why some methods should be protected you should read about Abstraction and Data Hiding in OOPS and Java.

Hope this helps !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM