package gradleapp;
public class MyApp{
public static void main(String[] args){
System.out.println("Hello,This is Sample MyApp");
System.out.println("build by Gradle!");
}
}
C:\Users\***\Documents\gradleapp2>gradle init
Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4] 2
Select implementation language:
1: C++
2: Groovy
3: Java
4: Kotlin
5: Scala
6: Swift
Enter selection (default: Java) [1..6] 3
Split functionality across multiple subprojects?:
1: no - only one application project
2: yes - application and library projects
Enter selection (default: no - only one application project) [1..2] 1
Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) [1..2] 1
Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no] no
Select test framework:
1: JUnit 4
2: TestNG
3: Spock
4: JUnit Jupiter
Enter selection (default: JUnit Jupiter) [1..4] 4
Project name (default: gradleapp2): gradleapp2
Source package (default: gradleapp2): gradleapp2
> Task :init
Get more help with your project: https://docs.gradle.org/7.3.1/samples/sample_building_java_applications.html
BUILD SUCCESSFUL in 1m 5s
プロジェクトのワークフォルダ配下に下記のディレクトリが作成されます。
また、下記のファイルが作成されます。
「build.gradle」 ビルドの定義はbuild.gradleファイルに記述します。
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/7.3.1/userguide/building_java_projects.html
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
// This dependency is used by the application.
implementation 'com.google.guava:guava:30.1.1-jre'
}
application {
// Define the main class for the application.
mainClass = 'gradleapp2.App'
}
/* 追加 JAR マニフェスト属性指定 */
jar {
manifest {
attributes 'Main-Class': 'gradleapp2.App'
}
}
tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
「settings.gradle」
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/7.3.1/userguide/multi_project_builds.html
*/
rootProject.name = 'gradleapp2'
include('app')
./app/src/main/java/gradleapp2/App.java
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package gradleapp2;
public class App {
public String getGreeting() {
return "Hello World!";
}
public static void main(String[] args) {
System.out.println(new App().getGreeting());
}
}
./app/src/test/java/gradleapp2/AppTest.java
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package gradleapp2;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class AppTest {
@Test void appHasAGreeting() {
App classUnderTest = new App();
assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
}
}
C:\Users\***\Documents\gradleapp2>gradle tasks
> Task :tasks
------------------------------------------------------------
Tasks runnable from root project 'gradleapp2'
------------------------------------------------------------
Application tasks
-----------------
run - Runs this project as a JVM application
Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles test classes.
Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.
Distribution tasks
------------------
assembleDist - Assembles the main distributions
distTar - Bundles the project as a distribution.
distZip - Bundles the project as a distribution.
installDist - Installs the project as a distribution as-is.
Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.
Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'gradleapp2'.
dependencies - Displays all dependencies declared in root project 'gradleapp2'.
dependencyInsight - Displays the insight into a specific dependency in root project 'gradleapp2'.
help - Displays a help message.
javaToolchains - Displays the detected java toolchains.
outgoingVariants - Displays the outgoing variants of root project 'gradleapp2'.
projects - Displays the sub-projects of root project 'gradleapp2'.
properties - Displays the properties of root project 'gradleapp2'.
tasks - Displays the tasks runnable from root project 'gradleapp2' (some of the displayed tasks may belong to subprojects).
Verification tasks
------------------
check - Runs all checks.
test - Runs the test suite.
To see all tasks and more detail, run gradle tasks --all
To see more detail about a task, run gradle help --task <task>
BUILD SUCCESSFUL in 3s
1 actionable task: 1 executed
(2)NetworkManager ネットワークの設定は、コンソール上で対話形式のツールのnmtui(NetworkManager Text User Interface)とコマンドベースのnmtcli(NetworkManager Command Line Interface)による方法があります。 ①nmtuiによる設定 $ mntui
(3)ネットワーク監視コマンド iproute2パッケージのコマンドについて記載します。 ip [オプション] オブジェクト [サブコマンド] オプション: -s:情報を詳しく表示する オブジェクト addr:ネットワークデバイスのIPアドレス route:ルーティングテーブルのエントリー link:ネットワークデバイス (例) ・デバイスの設定の一覧表示 $ ip addr ・指定したデバイスに設定されているIPアドレスの表示 $ ip addr show dev enp0s3 ・IPアドレスの追加 $ ip addr add 192.168.2.101/24 dev enp0s3 ・IPアドレスの追加 $ ip addr del 192.168.2.101/24 dev enp0s3
package test;
/*
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
*/
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
* Root resource (exposed at "myresource" path)
*/
@Path("myresource")
public class MyResource {
/**
* Method handling HTTP GET requests. The returned object will be sent
* to the client as "text/plain" media type.
*
* @return String that will be returned as a text/plain response.
*/
@GET
@Produces(MediaType.TEXT_PLAIN)
public Employee getIt() {
return "Got it!";
}
}
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
②HTTPリクエストのJavaメソッドへのマッピング用javax.ws.rsアノテーション @GET:HTTPのGETメソッドでアクセスされたとき呼び出されるメソッドで、URIにより識別されるリソースをクライアントに送信します。 @PUT:URIで識別される特定のリソースの作成(主に更新)を行います。 @DELETE:URIで識別されるリソースを削除します。 @POST:URIで識別される特定のリソースの作成(主に新規)を行います。 @HEAD:GETと同じ役割でレスポンス・ヘッダーのみを返し、メッセージはありません。 ③ @Produces(MediaType.TEXT_PLAIN) サービスが返すメディアタイプを指定することで、指定された型式でクライアントに返すことができます。
3.3 リソースファイルの改造 jersey-quickstart-webappmavenアーキタイプではテキストを返すのみでしたが、URIで指定したパラメータに従ってリソース(JSONファイル)を返すように改造します。 (1)RESTAPIのURI仕様 ・リクエスト GET /webapi/myresource/{id}/{name} ・レスポンス JSON形式{“id”:id,”name”:name}
(2)改造内容 ・「MyResource.java」
package test;
/*
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
*/
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
* Root resource (exposed at "myresource" path)
*/
@Path("myresource")
public class MyResource {
/**
* Method handling HTTP GET requests. The returned object will be sent
* to the client as "text/plain" media type.
*
* @return String that will be returned as a text/plain response.
*/
@GET
//@Produces(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/{name}")
public Employee getIt(@PathParam("id") int id,@PathParam("name") String name) {
Employee employee = new Employee(id, name);
return employee;
//return "Got it!";
}
}
・「Employee.java」
package test;
public class Employee {
/** 番号 */
public int id;
/** 名前 */
public String name;
/**
* コンストラクタ
* @param id 番号
* @param name 氏名
*/
public Employee(int id, String name) {
this.id = id;
this.name = name;
}
}
package test;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
test/java/test/AppTest.java
package test;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* Unit test for simple App.
*/
public class AppTest
{
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
}
}
(2)pom.xmlの作成
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>sample1</artifactId>
<version>1.0-SNAPSHOT</version>
<name>sample1</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>test.App</mainClass>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
<!-- Inline text elements -->
<p>mark tag to <mark>highlight</mark> text.</p>
<p>del tag to <del>This line of text is meant to be treated as deleted text.</del></p>
<p>s tag to <s>This line of text is meant to be treated as no longer accurate.</s></p>
<p>ins tag to <ins>This line of text is meant to be treated as an addition to the document.</ins></p>
<p>u tag to <u>This line of text will render as underlined.</u></p>
<p>small tag to <small>This line of text is meant to be treated as fine print.</small></p>
<p>strong tag to <strong>This line rendered as bold text.</strong></p>
<p>em tag to <em>This line rendered as italicized text.</em></p>
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<title>Bootstrapのページ</title>
</head>
<body>
<!-- Accordion(アコーディオン) -->
<div class="accordion" id="accordionExample">
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Accordion Item #1
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the first item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingTwo">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Accordion Item #2
</button>
</h2>
<div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingThree">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Accordion Item #3
</button>
</h2>
<div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the third item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js" integrity="sha384-q2kxQ16AaE6UbzuKqyBE9/u/KzioAlnx2maXQHiDX9d4/zp8Ok3f+M7DPm+Ib6IU" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.min.js" integrity="sha384-pQQkAEnwaBkjpqZ8RU1fF1AKtTcHJwFl3pblpTlHXybJjHpMYo79HY3hIi4NKxyj" crossorigin="anonymous"></script>
</body>
</html>