JAVA OPEN API2014. 2. 21. 00:16

* 기본 자바 탬플릿 : mvn archetype:generate -DgroupId=net.ucware -DartifactId=jungws01 -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false


* web 형식 탬플릿 : mvn archetype:generate -DgroupId=net.ucware -DartifactId=jungws07 -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false



* mvn 실행시 하위디렉토리의 pom.xml 파일을 읽어서 처리


* mvn 탬플릿 만든 후 이클립스 프로젝트로 만드는 명령 : mvn eclipse:eclipse 실행하면 pom 파일을 참조하여 classpath, project 파일이 생성된다 ( 그 후 이클립스에서 import 하면 됨 )


mvn help:effective-pom : 최상위pom 보는 방법


* maven-surefire 플러그인 : 단위테스트가 실패하더라도 다음 단계의 빌드를 실행하도록 설정할수 있음

    <testFailureIgnore>true</testFailureIgnore>

    

* 빌드시 src/main/java/ 자원이 복사 안되는 경우 

    <resources>

<resource>

<directory>src</directory>

<excludes>

<exclude>**/*.java</exclude>

</excludes>

</resource>

</resources>


* mvn package : finalName.packaging 파일이 target 디렉토리 밑에 생김 


* Dynamic Web Project 일때 pom.xml 파일이 있으면 그 파일 우측 마우스 클릭 하여 Run as - Maven 빌드 할수 있다.

 

* test Junit 실행 안하고 컴파일시

  - [이클립스에서실행] package 실행 test skip   =>(주의 사항 :  test 쪽 java 파일 compile 까지 안됨 )

  - [이클립스에서실행] 골 : compile:testCompile   ( test쪽만 다시 컴파일 함 )

 

* 프로필 사용 예

  환경설정 파일이 개발,검증,운영 다를때 pom.xml 에

 

<build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources-${environment}</directory>
            </resource>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
            </resource>    
        </resources>       
    </build>

 

<profiles>
        <profile>
            <id>dev</id>
            <properties>
                <environment>dev</environment>
            </properties>
        </profile>
        <profile>
            <id>qas</id>
            <properties>
                <environment>qas</environment>
            </properties>
        </profile>    

    </profiles>  

  각각 환경에 맞게 컴파일한다

 

공부해야할 것

 - 사내저장소 설치 (nexus??)

Posted by 선한열심
이클립스2014. 2. 20. 17:19

종종 서버가 실행이 안되는 경우가 발생하여 적어본다

 

1. maven clean한다

2. maven package 한다 ( package -> test 로도 가능 )

3. 이클립스 Refresh

4. 톰캣서버  clean 한다

5. 톰캣서버 실행한다 ( 톰캣서버 clean 후에는 다시 publish 된다 )

 

궁금증?? 톰캣서버 clean 후 publish 하면 안된다 +.+ 툴오류인지 내가 모르는 건지 모르겠다.

Posted by 선한열심
JAVA2014. 2. 19. 16:07

인증없이 전송 샘플 : http://blog.daum.net/_blog/BlogTypeView.do?blogid=0fK9x&articleno=618

전송 샘플 : http://kodejava.org/how-do-i-send-an-email-with-attachment/

                http://blog.naver.com/PostView.nhn?blogId=hmleena&logNo=63968842

 

윈도우7 SMTP 설치 : http://blog.naver.com/PostView.nhn?blogId=livingsens&logNo=40186294416&redirect=Dlog&widgetTypeCall=true

 

 

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage; 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SimpleMailTest {
    public static void main(String[] args) {    
        try {
            Properties props = new Properties();
            //props.put("mail.transport.protocol", "smtp");
            props.put("mail.smtp.host", "서버IP");
            props.put("mail.smtp.port", "서버PORT");      
            props.put("mail.smtp.auth", "false"); 
            //props.put("mail.smtp.starttls.enable","true");
            Authenticator authenticator = new Authenticator()
            {
            protected PasswordAuthentication getPasswordAuthentication()
            {
                return new PasswordAuthentication(null,null);
              }
            };
            //props.put("mail.smtp.auth", "true"); 
            //props.put("mail.smtp.starttls.enable", "false");   
            System.out.println( "2" );
            Session session = Session.getInstance(props) ;
            //Session session = Session.getDefaultInstance(props) ;
            System.out.println("2");
           
           
            InternetAddress fromAddress = new InternetAddress("jungws55@daum.net");
            InternetAddress toAddress   = new InternetAddress("jungws55@nate.com");
           

            MimeMessage message = new MimeMessage(session);
            message.setFrom(fromAddress);
            message.addRecipient(Message.RecipientType.TO, toAddress );
            message.setSubject("제목");
            message.setContent("내용"," text/html; charset=KSC5601");
            Transport.send(message);
            System.out.println("[{}] 메일 발송 성공 jungws55@nate.com");


         } catch (MessagingException e) {
             System.out.println(e);
         }


     }
}

 

'JAVA' 카테고리의 다른 글

[ERROR] java 오류 정리  (0) 2014.02.26
Socket으로 Mail 전송 샘플  (0) 2014.02.24
java.lang.reflect.Method 샘플  (0) 2013.12.05
Annotation Example  (0) 2013.12.05
static 키워드  (0) 2013.12.04
Posted by 선한열심