까먹지 말자.. 으휴..

기능 설명 1 설명 2
동일한 단어에 대하여 치환을 할 경우 1 치환 대상 단어에서 cw를 입력, 해당 단어는 삭제
2 편집 모드로 변하여 치환할 단어를 입력한 뒤 Esc 키를 클릭
3 이후부터 치환 대상 단어에 . 키(반복 작업)를 클릭
 
커서가 위치한 줄부터 n번째까지 들여쓰기 - visual block mode

1 커서 자리에서 v 키(비주얼 블럭 모드)를 클릭
2 n번째가 커서를 이동
2.1 커서의 컬럼 위치와는 상관이 없다
3 space + > 키를 클릭 (한 단계의 들여쓰기)
3.1 space + >> 키 (두 단계의 들여쓰기)
3.2 숫자 + space + > (숫자 단계까지 들여쓰기)
- command mode

 

Posted by 테리
:

위와 같이 tomcat7의 이미지를 설치했는데, repository가 동일해서 당황하게 됨

 

이때, docker의 두개의 명령어가 있으니, 참고해서 변경하자요

꼭! 동일한 이름 외에도 별도의 이름으로 변경할 때 사용하면 될 듯

선택 1 - docker image tag 'repository_name':'tag_name' 'repository_rename':'tag_name'

선택 2 - docker image tag 'image id' 'repository_rename':'tag_name'

 

위와 같을 경우 선택 1은 동일한 이름이므로, 선택 2로 변경이 가능하다

 

 

https://stackoverflow.com/questions/25211198/docker-how-to-change-repository-name-or-rename-image

'개발 > Docker' 카테고리의 다른 글

docker에 tomcat 이미지 설치  (1) 2024.11.28
맥북에 docker 설치  (0) 2024.11.26
Posted by 테리
:

1 tomcat 이미지 설치

macbook]$ docker search tomcat

..tomcat과 관련된 이미지들이 주루룩

macbook]$ docker pull tomcat

2 이미지를 container로 

macbook]$ docker run -d --name tomcat_container -p 8080:8080 tomcat

=> run: Run a command in a new container

=> -d는 daemon

=> --name string: Assign a name to the container

* docker COMMAND --help

* Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

3 container의 정보 확인

macbook]$ docker container ls

=> container: Manage containers

=> ls: List containers

4 container에 서비스 파일 밀어넣기

4.1 container의 cli 접속

macbook]$ docker exec -it tomcat_container /bin/bash

root 계정으로 들어간다는 것을 기억해야 겠네

4.2 ROOT 디렉토리 생성

tomcat_container]% mkdir /usr/local/tomcat/webapps/ROOT

4.3 cli에서 나가기

tomcat_container]% exit

4.4 서비스 파일을 container 안으로 밀어넣기

macbook]$ docker cp ./server.war tomcat_container:/usr/local/tomcat/webapps/ROOT/

4.5 container cli에서 .war 파일 풀기

4.5.1 선행으로 4.1을 진행

4.5.2 ROOT 디렉토리로 이동

4.5.3 .war 풀기

tomcat_container]$ unzip server.war

으악 command not found

5 container cli에 unzip 설치

5.1 선행으로 4.1을 진행

5.2 container cli는 ubuntu os 이더라

5.3 apt-get 명령어로 설치

tomcat_container]$ apt-get update && apt-get install -y unzip

다시 앞으로 돌아가면

4.5.3 .war 풀기

tomcat_container]$ unzip server.war

4.5.4 404 에러

4.5.5 앞서 1번 항목에 내려받은 tomcat 이미지의 버전이 10.x이고, java는 2x

tomcat 설정을 바꿔 보았으나, 진도에 차도가 없어서...

tomcat7에 java1.8을 설치 후 서비스에 접근이 가능해 짐

앗. 이때 올라간 이미지의 repository 명이 동일하여 당황

다음편에...

 

 

/* 참, container cli 특징..

docker install에서 java1.8을 찾지 못하지만, container cli에서 apt-get 또는 yum을 통해서 각종 tools을 받을 수가 있다

그리고, container를 삭제(rm)한 후 다시 서비스를 하면, 앞서 설치한 내용들은 모두 날아간다는 점

*/

 

.. 암튼 이렇게 tomcat service는 마무리..

 

'개발 > Docker' 카테고리의 다른 글

docker image의 repository 이름이 동일할 경우 변경하는 방법  (0) 2024.11.28
맥북에 docker 설치  (0) 2024.11.26
Posted by 테리
:

 

Using Java Reflection

By Glen McCluskey
January 1998

Technical Article

Reflection is a feature in the Java programming language. It allows an executing Java program to examine or "introspect" upon itself, and manipulate internal properties of the program. For example, it's possible for a Java class to obtain the names of all its members and display them.

The ability to examine and manipulate a Java class from within itself may not sound like very much, but in other programming languages this feature simply doesn't exist. For example, there is no way in a Pascal, C, or C++ program to obtain information about the functions defined within that program.

One tangible use of reflection is in JavaBeans, where software components can be manipulated visually via a builder tool. The tool uses reflection to obtain the properties of Java components (classes) as they are dynamically loaded.

A Simple Example

To see how reflection works, consider this simple example:

Copy
import java.lang.reflect.*;

 
   public class DumpMethods {
      public static void main(String args[])
      {
         try {
            Class c = Class.forName(args[0]);
            Method m[] = c.getDeclaredMethods();
            for (int i = 0; i < m.length; i++)
            System.out.println(m[i].toString());
         }
         catch (Throwable e) {
            System.err.println(e);
         }
      }
   }

For an invocation of:

java DumpMethods java.util.Stack

the output is:

Copy
public java.lang.Object java.util.Stack.push(

    java.lang.Object)
   public synchronized 
     java.lang.Object java.util.Stack.pop()
   public synchronized
      java.lang.Object java.util.Stack.peek()
   public boolean java.util.Stack.empty()
   public synchronized 
     int java.util.Stack.search(java.lang.Object)

That is, the method names of class java.util.Stack are listed, along with their fully qualified parameter and return types.

This program loads the specified class using class.forName, and then calls getDeclaredMethods to retrieve the list of methods defined in the class. java.lang.reflect.Method is a class representing a single class method.

Setting Up to Use Reflection

The reflection classes, such as Method, are found in java.lang.reflect. There are three steps that must be followed to use these classes. The first step is to obtain a java.lang.Class object for the class that you want to manipulate. java.lang.Class is used to represent classes and interfaces in a running Java program.

One way of obtaining a Class object is to say:

Class c = Class.forName("java.lang.String"); to get the Class object for String. Another approach is to use: Class c = int.class; or Class c = Integer.TYPE; to obtain Class information on fundamental types. The latter approach accesses the predefined TYPE field of the wrapper (such as Integer) for the fundamental type.

The second step is to call a method such as getDeclaredMethods, to get a list of all the methods declared by the class.

Once this information is in hand, then the third step is to use the reflection API to manipulate the information. For example, the sequence:

Class c = Class.forName("java.lang.String"); Method m[] = c.getDeclaredMethods(); System.out.println(m[0].toString());

will display a textual representation of the first method declared in String.

In the examples below, the three steps are combined to present self contained illustrations of how to tackle specific applications using reflection.

Simulating the instanceof Operator

Once Class information is in hand, often the next step is to ask basic questions about the Class object. For example, the Class.isInstance method can be used to simulate the instanceof operator:

Copy
class A {}

   public class instance1 {
      public static void main(String args[])
      {
         try {
            Class cls = Class.forName("A");
            boolean b1 
              = cls.isInstance(new Integer(37));
            System.out.println(b1);
            boolean b2 = cls.isInstance(new A());
            System.out.println(b2);
         }
         catch (Throwable e) {
            System.err.println(e);
         }
      }
   }

In this example, a Class object for A is created, and then class instance objects are checked to see whether they are instances of A. Integer(37) is not, but new A() is.

Finding Out About Methods of a Class

One of the most valuable and basic uses of reflection is to find out what methods are defined within a class. To do this the following code can be used:

Copy
import java.lang.reflect.*;

   public class method1 {
      private int f1(
       Object p, int x) throws NullPointerException
      {
         if (p == null)
            throw new NullPointerException();
         return x;
      }
        
      public static void main(String args[])
      {
         try {
           Class cls = Class.forName("method1");
        
            Method methlist[] 
              = cls.getDeclaredMethods();
            for (int i = 0; i < methlist.length;
               i++) {  
               Method m = methlist[i];
               System.out.println("name 
                 = " + m.getName());
               System.out.println("decl class = " +
                              m.getDeclaringClass());
               Class pvec[] = m.getParameterTypes();
               for (int j = 0; j < pvec.length; j++)
                  System.out.println("
                   param #" + j + " " + pvec[j]);
               Class evec[] = m.getExceptionTypes();
               for (int j = 0; j < evec.length; j++)
                  System.out.println("exc #" + j 
                    + " " + evec[j]);
               System.out.println("return type = " +
                                  m.getReturnType());
               System.out.println("-----");
            }
         }
         catch (Throwable e) {
            System.err.println(e);
         }
      }
   }

The program first gets the Class description for method1, and then calls getDeclaredMethods to retrieve a list of Method objects, one for each method defined in the class. These include public, protected, package, and private methods. If you use getMethods in the program instead of getDeclaredMethods, you can also obtain information for inherited methods.

Once a list of the Method objects has been obtained, it's simply a matter of displaying the information on parameter types, exception types, and the return type for each method. Each of these types, whether they are fundamental or class types, is in turn represented by a Class descriptor. The output of the program is:

Copy
name = f1
   decl class = class method1
   param #0 class java.lang.Object
   param #1 int
   exc #0 class java.lang.NullPointerException
   return type = int
   -----
   name = main
   decl class = class method1
   param #0 class [Ljava.lang.String;
   return type = void
   -----

Obtaining Information About Constructors

A similar approach is used to find out about the constructors of a class. For example:

Copy
import java.lang.reflect.*;
        
   public class constructor1 {
      public constructor1()
      {
      }
        
      protected constructor1(int i, double d)
      {
      }
        
      public static void main(String args[])
      {
         try {
           Class cls = Class.forName("constructor1");
        
           Constructor ctorlist[]
               = cls.getDeclaredConstructors();
         for (int i = 0; i < ctorlist.length; i++) {
               Constructor ct = ctorlist[i];
               System.out.println("name 
                 = " + ct.getName());
               System.out.println("decl class = " +
                            ct.getDeclaringClass());
               Class pvec[] = ct.getParameterTypes();
               for (int j = 0; j < pvec.length; j++)
                  System.out.println("param #" 
                     + j + " " + pvec[j]);
               Class evec[] = ct.getExceptionTypes();
               for (int j = 0; j < evec.length; j++)
                  System.out.println(
                    "exc #" + j + " " + evec[j]);
               System.out.println("-----");
            }
          }
          catch (Throwable e) {
             System.err.println(e);
          }
      }
   }

There is no return-type information retrieved in this example, because constructors don't really have a true return type.

When this program is run, the output is:

Copy
name = constructor1
   decl class = class constructor1
   -----
   name = constructor1
   decl class = class constructor1
   param #0 int
   param #1 double
   -----

Finding Out About Class Fields

It's also possible to find out which data fields are defined in a class. To do this, the following code can be used:

Copy
import java.lang.reflect.*;
        
   public class field1 {
      private double d;
      public static final int i = 37;
      String s = "testing";
        
      public static void main(String args[])
      {
         try {
            Class cls = Class.forName("field1");
        
            Field fieldlist[] 
              = cls.getDeclaredFields();
            for (int i 
              = 0; i < fieldlist.length; i++) {
               Field fld = fieldlist[i];
               System.out.println("name
                  = " + fld.getName());
               System.out.println("decl class = " +
                           fld.getDeclaringClass());
               System.out.println("type
                  = " + fld.getType());
               int mod = fld.getModifiers();
               System.out.println("modifiers = " +
                          Modifier.toString(mod));
               System.out.println("-----");
            }
          }
          catch (Throwable e) {
             System.err.println(e);
          }
       }
   }

This example is similar to the previous ones. One new feature is the use of Modifier. This is a reflection class that represents the modifiers found on a field member, for example "private int". The modifiers themselves are represented by an integer, and Modifier.toString is used to return a string representation in the "official" declaration order (such as "static" before "final"). The output of the program is:

Copy
name = d
   decl class = class field1
   type = double
   modifiers = private
   -----
   name = i
   decl class = class field1
   type = int
   modifiers = public static final
   -----
   name = s
   decl class = class field1
   type = class java.lang.String
   modifiers =
   -----

As with methods, it's possible to obtain information about just the fields declared in a class (getDeclaredFields), or to also get information about fields defined in superclasses (getFields).

Invoking Methods by Name

So far the examples that have been presented all relate to obtaining class information. But it's also possible to use reflection in other ways, for example to invoke a method of a specified name.

To see how this works, consider the following example:

Copy
import java.lang.reflect.*;
        
   public class method2 {
      public int add(int a, int b)
      {
         return a + b;
      }
        
      public static void main(String args[])
      {
         try {
           Class cls = Class.forName("method2");
           Class partypes[] = new Class[2];
            partypes[0] = Integer.TYPE;
            partypes[1] = Integer.TYPE;
            Method meth = cls.getMethod(
              "add", partypes);
            method2 methobj = new method2();
            Object arglist[] = new Object[2];
            arglist[0] = new Integer(37);
            arglist[1] = new Integer(47);
            Object retobj 
              = meth.invoke(methobj, arglist);
            Integer retval = (Integer)retobj;
            System.out.println(retval.intValue());
         }
         catch (Throwable e) {
            System.err.println(e);
         }
      }
   }

Suppose that a program wants to invoke the add method, but doesn't know this until execution time. That is, the name of the method is specified during execution (this might be done by a JavaBeans development environment, for example). The above program shows a way of doing this.

getMethod is used to find a method in the class that has two integer parameter types and that has the appropriate name. Once this method has been found and captured into a Method object, it is invoked upon an object instance of the appropriate type. To invoke a method, a parameter list must be constructed, with the fundamental integer values 37 and 47 wrapped in Integer objects. The return value (84) is also wrapped in an Integer object.

Creating New Objects

There is no equivalent to method invocation for constructors, because invoking a constructor is equivalent to creating a new object (to be the most precise, creating a new object involves both memory allocation and object construction). So the nearest equivalent to the previous example is to say:

Copy
import java.lang.reflect.*;
        
   public class constructor2 {
      public constructor2()
      {
      }
        
      public constructor2(int a, int b)
      {
         System.out.println(
           "a = " + a + " b = " + b);
      }
        
      public static void main(String args[])
      {
         try {
           Class cls = Class.forName("constructor2");
           Class partypes[] = new Class[2];
            partypes[0] = Integer.TYPE;
            partypes[1] = Integer.TYPE;
            Constructor ct 
              = cls.getConstructor(partypes);
            Object arglist[] = new Object[2];
            arglist[0] = new Integer(37);
            arglist[1] = new Integer(47);
            Object retobj = ct.newInstance(arglist);
         }
         catch (Throwable e) {
            System.err.println(e);
         }
      }
   }

which finds a constructor that handles the specified parameter types and invokes it, to create a new instance of the object. The value of this approach is that it's purely dynamic, with constructor lookup and invocation at execution time, rather than at compilation time.

Changing Values of Fields

Another use of reflection is to change the values of data fields in objects. The value of this is again derived from the dynamic nature of reflection, where a field can be looked up by name in an executing program and then have its value changed. This is illustrated by the following example:

Copy
import java.lang.reflect.*;
        
   public class field2 {
      public double d;
        
      public static void main(String args[])
      {
         try {
            Class cls = Class.forName("field2");
            Field fld = cls.getField("d");
            field2 f2obj = new field2();
            System.out.println("d = " + f2obj.d);
            fld.setDouble(f2obj, 12.34);
            System.out.println("d = " + f2obj.d);
         }
         catch (Throwable e) {
            System.err.println(e);
         }
      }
   }

In this example, the d field has its value set to 12.34.

Using Arrays

One final use of reflection is in creating and manipulating arrays. Arrays in the Java language are a specialized type of class, and an array reference can be assigned to an Object reference.

To see how arrays work, consider the following example:

Copy
import java.lang.reflect.*;
        
   public class array1 {
      public static void main(String args[])
      {
         try {
            Class cls = Class.forName(
              "java.lang.String");
            Object arr = Array.newInstance(cls, 10);
            Array.set(arr, 5, "this is a test");
            String s = (String)Array.get(arr, 5);
            System.out.println(s);
         }
         catch (Throwable e) {
            System.err.println(e);
         }
      }
   }

This example creates a 10-long array of Strings, and then sets location 5 in the array to a string value. The value is retrieved and displayed.

A more complex manipulation of arrays is illustrated by the following code:

Copy
import java.lang.reflect.*;
        
   public class array2 {
      public static void main(String args[])
      {
         int dims[] = new int[]{5, 10, 15};
         Object arr 
           = Array.newInstance(Integer.TYPE, dims);
        
         Object arrobj = Array.get(arr, 3);
         Class cls = 
           arrobj.getClass().getComponentType();
         System.out.println(cls);
         arrobj = Array.get(arrobj, 5);
         Array.setInt(arrobj, 10, 37);
        
         int arrcast[][][] = (int[][][])arr;
         System.out.println(arrcast[3][5][10]);
      }
   }

This example creates a 5 x 10 x 15 array of ints, and then proceeds to set location [3][5][10] in the array to the value 37. Note here that a multi-dimensional array is actually an array of arrays, so that, for example, after the first Array.get, the result in arrobj is a 10 x 15 array. This is peeled back once again to obtain a 15-long array, and the 10th slot in that array is set using Array.setInt.

Note that the type of array that is created is dynamic, and does not have to be known at compile time.

Summary

Java reflection is useful because it supports dynamic retrieval of information about classes and data structures by name, and allows for their manipulation within an executing Java program. This feature is extremely powerful and has no equivalent in other conventional languages such as C, C++, Fortran, or Pascal.

Glen McCluskey has focused on programming languages since 1988. He consults in the areas of Java and C++ performance, testing, and technical documentation.

 

 

https://www.oracle.com/technical-resources/articles/java/javareflection.html

Posted by 테리
:

맥북에 docker 설치

개발/Docker 2024. 11. 26. 21:22 |

1 https://docs.docker.com/desktop/setup/install/mac-install/

 

Mac

Install Docker for Mac to get started. This guide covers system requirements, where to download, and instructions on how to install and update.

docs.docker.com

여기서, 본인의 cpu 사양에 맞게끔 선택 (난, Intel chil)

으악! 무작정 설치하면 안되네요. 제 사양이 낮은 관계 다시 설치를 진행

먼저, 4.20.0 버전을 찾아야 해서 docker의 realse  버전 페이지로 들어가서 해당 버전이 있네요

근데, 아무리 링크된 곳을 눌려도 다운로드가 되지 않아요

그래서 결국 Docker Desktop 4.25.0 Not Installing On macOS Big Sur 11.7.10 · Issue #7071 · docker/for-mac

 

Docker Desktop 4.25.0 Not Installing On macOS Big Sur 11.7.10 · Issue #7071 · docker/for-mac

Description Docker Desktop 4.25.0 Not Installing On macOS Big Sur 11.7.10. Thus, I'm getting the following message when I attempt to execute it via the icon: You have macOS 11.7.10. The application...

github.com

3 설치된 docker를 실행했더니

망했네요.{z-index: 9999; -webkit-transform: translate3d(0, 0, 9999px); position: f

오류가 떠네요. 된장

결국, 깔려있던 스팀의 바둑 게임을 삭제하고, 또 어디서 받은 것인지 알 수 없는 .dmg를 클릭했더니..

이건 제대로 동작을 하네요. 상단바에 고래 아이콘도 올라오고

설치된 버전은 Docker version 20.10.16, build aa7e414가 나오네요

 

설치도 힘드네요.

 

맥북 m2 가지고 싶네요.. 당근!

 

Posted by 테리
:

JSONObject 형식의 String 값을 JSONObject에 넣으면 `"` 기호 앞에 `\` 기호가 붙게 되는데, 한동안 이것을 제거하는 방법을 몰라서 그대로 남겼는데..

 

이제야?? 아니면 알고 있으면서도 잊어버린 것을 머리의 기억을 더 이상 믿지 못하여 기록을 남겨야겠다

JSONObject jso = new JSONObject();

JSONParser jsp = new JSONParser();

String strJSONObject = "{\"key\":\"value\"}";

jso.put("original", strJSONObject);

jso.put("parse", jsp.parse(strJSONObject));

print:

original => \"{\\"key\\":\\"value\\"}\"

parse => {"key":"value"}

'개발 > Java' 카테고리의 다른 글

Using Java Reflection By Glen McCluskey  (0) 2024.11.27
javacore 파일 분석  (0) 2021.06.10
Java 파서 중 외부 DTD 참조 방지 설정  (0) 2021.01.15
Posted by 테리
:

해결: Server 키보드의 Scroll Lock을 해제

원인: Server 키보드의 Scroll Lock이 언제가 부터 켜저 있음

 

1 Barrier 툴을 띄운 후 F2를 클릭하면 로그창이 뜨는데, 이때 Client와 연결이 되었다는 로그까지 확인이 되었는데

2 마우스가 macbook으로 넘어가지 않는 현상

3 혹시나 싶어, 방화벽도 다 풀어보았으나 해결이 되지 않음

4 걸색해 보니, F4(설정)의 `Networking => Enable SSL`을 체크 해지를 하면 된다고 하였으나, 해결이 되지 않음

4 검색을 해 보니 Scroll Lock이 걸릴 경우 마우스가 넘어가지 못하는 현상이 있다는 사실

5 암튼 살짝, 황당했다능...

 

https://askubuntu.com/questions/1409533/barrier-does-not-work-for-linux-to-windows-connection

Posted by 테리
:

1 클래스의 메소드 팝업(content) 배경색 변경

1.2 Window > Preferences > General > Appearance > Colors and Fonts > Basic > Content Assist background color를 클릭하고 Edit 버튼 클릭

1.2.1 색을 변경하여 확인 > Apply > Apply and Close 

1.3 변경된 클래스의 메소드 팝업(content) 배경색

 

Posted by 테리
:

1 Vrapper: 이클립스 에디트 입력 방식을 linux의 vim 입력 방식으로 사용

 

2 DevStyle: 요즘 추세인 어두운 테마

 

3 quick search for eclipse: 기존의 Ctrl+H로 전체 검색 기능을 사용하였다면, 이것은 Ctrl+Shift+L로 검색

 

4 editbox: 

 

5 grep console:

Posted by 테리
:

1 현상

1.1 이클립스를 띄우거나, 코드 수정 등등 각종 액션이 된 후

1.2 갑자기 마우스 클릭이 안되고, 다시금 마우스 클릭시 하아얀 모달 화면이 뜸

1.3 이클립스 우측 하단에 "remote system explorer operation"이라는 메시지가 나타다고 백그라운드 프로그래바가 동작

 

- 바쁠 때 참으로 속이 답답해지는 이클립스 현상

- 버릴 수도 없고, 대체 가능한 툴도 못 찾고

- 이럴 때 다음과 같은 설정을 해 보자

Window > Preferences > General > Startup and Shutdown: RES UI > Uncheck

 

 

 

 

Window > Preferences > Remote Systems : Re-open Remote Systems view to previous state > Uncheck

Posted by 테리
: