Téléchargez "apache-maven-3.6.2-bin.zip" depuis le site suivant https://maven.apache.org/download.cgi
Développez et passez le chemin vers le bac. Cette fois, il était réglé sur "D: \ apache-maven-3.6.2 \ bin".
mvn -version
OK si vous commencez par. Cette fois, ce qui suit était affiché, j'ai donc installé le JDK.
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
Le JDK téléchargé est «Amazon Corretto 8»
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-28T00:06:16+09:00)
Maven home: D:\apache-maven-3.6.2\bin\..
Java version: 1.8.0_232, vendor: Amazon.com Inc., runtime: C:\Program Files\Amazon Corretto\jdk1.8.0_232\jre
Default locale: ja_JP, platform encoding: MS932
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Cela a fonctionné en toute sécurité.
Configurez un référentiel local. Ouvrez Maven \ conf \ settings.xml et définissez n'importe quel emplacement comme référentiel local comme indiqué ci-dessous.
settings.xml
<localRepository>D:/apache-maven-3.6.2/repository/</localRepository>
À titre d'exemple, créez un carnet d'adresses dans l'application SWT.
L'application se compose de trois pots.
· Vue
・ Domaine
· Infrastructure
-Id de groupe: un nom qui ne chevauche pas tous les projets. Nom du package (domaine + nom du projet) -Id de l'artefact: nom du fichier Jar sans la version
Il a une chaîne nommée Nom et Adresse 1, Adresse 2, Date nommée Anniversaire et un int pour la gestion.
Address.java
package ml.kerotori.app.domain;
import java.util.Date;
public class Address {
private int no; //Numéro de gestion
private String Name; //Nom
private String Address1; //Adresse 1
private String Address2; //Adresse 2
private Date Birthday; //anniversaire
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getAddress1() {
return Address1;
}
public void setAddress1(String address1) {
Address1 = address1;
}
public String getAddress2() {
return Address2;
}
public void setAddress2(String address2) {
Address2 = address2;
}
public Date getBirthday() {
return Birthday;
}
public void setBirthday(Date birthday) {
Birthday = birthday;
}
}
[ERROR]L'option source 5 n'est actuellement pas prise en charge. Veuillez utiliser 6 ou une version ultérieure.
[ERROR]Option cible 1.5 n'est actuellement pas pris en charge. 1.Veuillez utiliser 6 ou une version ultérieure.
pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
L'image entière est la suivante.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.125 s
[INFO] Finished at: 2019-11-03T22:29:41+09:00
[INFO] ------------------------------------------------------------------------
Enregistrez le carnet d'adresses dans un fichier XML afin qu'il puisse être lu.
Save.java
package ml.kerotori.app.infrastructure.core;
import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
public interface Save<T> {
public static <T> boolean saveXml(String fileName, T obj) {
//Enregistrer les données d'objet
try (XMLEncoder encoder = new XMLEncoder(
new BufferedOutputStream(
new FileOutputStream(fileName)))) {
encoder.writeObject(obj);
} catch (FileNotFoundException e) {
return false;
}catch(Exception e) {
return false;
}
return true;
}
}
Load.java
package ml.kerotori.app.infrastructure.core;
import java.beans.XMLDecoder;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public interface Load<T> {
@SuppressWarnings("unchecked")
public static <T> T loadXml(String fileName) {
try (XMLDecoder decoder = new XMLDecoder(
new BufferedInputStream(
new FileInputStream(fileName)))) {
return (T) decoder.readObject();
} catch (FileNotFoundException e) {
return null;
}catch(Exception e) {
return null;
}
}
}
AddressDao.java
package ml.kerotori.app.infrastructure.dao;
import java.io.Serializable;
import ml.kerotori.app.domain.Address;
import ml.kerotori.app.infrastructure.core.Load;
import ml.kerotori.app.infrastructure.core.Save;
public class AddressDao implements Serializable,Save<Address>, Load<Address> {
private Address address;
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public static Address Load(int no) {
return Load.loadXml(no + ".xml");
}
public boolean Save() {
return Save.saveXml(this.address.getNo() + ".xml", address);
}
}
Ajoutez ce qui suit à l'infrastructure pom.xml.
xml.pom.xml
<dependencies>
<dependency>
<groupId>ml.kerotori.app</groupId>
<artifactId>Domain</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
AddressTest.java
package ml.kerotori.app.infrastructure.dao;
import static org.junit.jupiter.api.Assertions.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.junit.jupiter.api.Test;
import ml.kerotori.app.domain.Address;
class AddressDaoTest {
@Test
void SaveTest1() {
Address address = new Address();
address.setNo(1);
address.setName("Ichiro Sato");
address.setAddress1("Hokkaido");
address.setAddress2("Sapporo");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
Date date = null;
try {
date = sdf.parse("1990/10/11");
} catch (ParseException e) {
//Bloc de capture généré automatiquement TODO
e.printStackTrace();
}
address.setBirthday(date);
AddressDao dao = new AddressDao();
dao.setAddress(address);
assertTrue(dao.Save());
}
@Test
void LoadTest1() {
Address address = AddressDao.Load(1);
assertEquals("Ichiro Sato", address.getName());
}
}
pom.xml(Projet parent)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<workingDirectory>${project.basedir}/src/test/resources</workingDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
</plugin>
Si le test échoue, l'exécution du projet Maven-Update peut aider.
Concernant SWT pour Windows, la nouvelle version (4.13) est pour 64 bits et ne fonctionne pas en environnement 32 bits. https://download.eclipse.org/eclipse/downloads/drops4/R-4.13-201909161045/ La dernière version 32 bits est la 3.8.2 ci-dessous? https://archive.eclipse.org/eclipse/downloads/drops/R-3.8.2-201301310800/
Dans Eclipse Marketplace, saisissez "WindowBuilder" dans la recherche et l'installation.
https://repo1.maven.org/maven2/org/eclipse/platform/org.eclipse.swt.win32.win32.x86/3.108.0/
Tout ce que j'avais à faire était de supprimer physiquement le dossier.
J'ai abandonné et j'ai décidé de le télécharger moi-même et de l'enregistrer manuellement dans le référentiel.
Définissez ce qui suit dans pom.xml de View.
pom.xml
<profiles>
<profile>
<id>windows_x86</id>
<activation>
<os>
<family>Windows</family>
<arch>x86</arch>
</os>
</activation>
<dependencies>
<dependency>
<groupId>swt</groupId>
<artifactId>swt-win32-x86</artifactId>
<version>3.8.2</version>
<type>jar</type>
</dependency>
</dependencies>
</profile>
<profile>
<id>windows-x86_64</id>
<activation>
<os>
<family>Windows</family>
<arch>amd64</arch>
</os>
</activation>
<dependencies>
<dependency>
<groupId>swt</groupId>
<artifactId>swt-win32-x86_64</artifactId>
<version>3.8.2</version>
<type>jar</type>
</dependency>
</dependencies>
</profile>
</profiles>
Téléchargez "swt-3.8.2-win32-win32-x86.zip" et "swt-3.8.2-win32-win32-x86_64.zip" et décompressez-les pour trouver "swt.jar". Modifiez le nom comme suit et enregistrez-le dans le dossier "D: \ swt". swt-3.8.2-win32-x86.jar swt-3.8.2-win32-x86_64.jar
Enregistrez-vous manuellement dans le référentiel avec la commande suivante.
SET REPO_URL=file:D:/apache-maven-3.6.2/repository/
mvn deploy:deploy-file -DrepositoryId=ml.kerotori.app -Durl=%REPO_URL% -Dfile=d:\swt\swt-3.8.2-win32-x86.jar -DgroupId=swt -DartifactId=swt-win32-x86 -Dversion=3.8.2 -Dpackaging=jar
mvn deploy:deploy-file -DrepositoryId=ml.kerotori.app -Durl=%REPO_URL% -Dfile=d:\swt\swt-3.8.2-win32-x86_64.jar -DgroupId=swt -DartifactId=swt-win32-x86_64 -Dversion=3.8.2 -Dpackaging=jar
L'erreur n'a pas disparu pour une raison quelconque, mais lorsque j'ai effacé l'erreur et l'ai exécutée, cela fonctionnait normalement.
Pour le moment, seul fonctionnement normal. La vérification de la valeur d'entrée est omise.
AddressView.java
package ml.kerotori.app.view;
import java.util.Date;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import ml.kerotori.app.domain.Address;
import ml.kerotori.app.infrastructure.dao.AddressDao;
public class AddressView {
protected Shell shell;
private Text txtNo;
private Text txtName;
private Text txtAddress1;
private Text txtAddress2;
private Text txtBirtyday;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
AddressView window = new AddressView();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
shell.setLayout(new GridLayout(2, false));
Label lblNo = new Label(shell, SWT.NONE);
lblNo.setText("No");
txtNo = new Text(shell, SWT.BORDER);
txtNo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label label = new Label(shell, SWT.NONE);
label.setText("Nom");
txtName = new Text(shell, SWT.BORDER);
txtName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label label_1 = new Label(shell, SWT.NONE);
label_1.setText("Adresse 1");
txtAddress1 = new Text(shell, SWT.BORDER);
txtAddress1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label label_2 = new Label(shell, SWT.NONE);
label_2.setText("Adresse 2");
txtAddress2 = new Text(shell, SWT.BORDER);
txtAddress2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label label_3 = new Label(shell, SWT.NONE);
label_3.setText("anniversaire");
txtBirtyday = new Text(shell, SWT.BORDER);
txtBirtyday.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Button btnSave = new Button(shell, SWT.NONE);
btnSave.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
AddressDao dao = new AddressDao();
Address address = new Address();
address.setNo(Integer.parseInt(txtNo.getText()));
address.setName(txtName.getText());
address.setAddress1(txtAddress1.getText());
address.setAddress2(txtAddress2.getText());
address.setBirthday(new Date(txtBirtyday.getText()));
dao.setAddress(address);
if(dao.Save()) {
MessageBox msgBox = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
msgBox.setText("MessageBox");
msgBox.setMessage("Inscription réussie");
int reply = msgBox.open();
}else {
MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
msgBox.setText("MessageBox");
msgBox.setMessage("Échec d'enregistrement");
int reply = msgBox.open();
}
}
});
btnSave.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 2, 1));
btnSave.setText("enregistrement");
}
}
pom.xml
<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>
<parent>
<groupId>ml.kerotori.app</groupId>
<artifactId>SWTsample</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>View</artifactId>
<profiles>
<profile>
<id>windows_x86</id>
<activation>
<os>
<family>Windows</family>
<arch>x86</arch>
</os>
</activation>
<dependencies>
<dependency>
<groupId>swt</groupId>
<artifactId>swt-win32-x86</artifactId>
<version>3.8.2</version>
<type>jar</type>
</dependency>
</dependencies>
</profile>
<profile>
<id>windows-x86_64</id>
<activation>
<os>
<family>Windows</family>
<arch>amd64</arch>
</os>
</activation>
<dependencies>
<dependency>
<groupId>swt</groupId>
<artifactId>swt-win32-x86_64</artifactId>
<version>3.8.2</version>
<type>jar</type>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>ml.kerotori.app</groupId>
<artifactId>Domain</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ml.kerotori.app</groupId>
<artifactId>Infrastructure</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Si vous créez pom.xml du projet parent comme suit, un module est créé dans View.
pom.xml
<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>ml.kerotori.app</groupId>
<artifactId>SWTsample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>View</module>
<module>Infrastructure</module>
<module>Domain</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<finalName>SWTsample</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>ml.kerotori.app.view.AddressView</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- configure the plugin here -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Réglez en référence à ce qui suit. https://qiita.com/cotrpepe/items/7cafaacb538425a78f1f
Pour votre information. https://github.com/kero1976/SWTsample
Recommended Posts