maven项目的建立中出错

突然想学maven,没想到建项目的过程,就经历的各种坑。。。

一开始建的是maven project,并且勾选了simple project,如图:

很顺利没有任何问题,项目结构是这样

 

看起来过于简单,于是一番查询后,开始进一步尝试,选择quickstart模板

 报错: Missing artifact junit:junit:jar:4.5

解决:Window——priferences——Myeclipse——Maven,将offline设置为不选,随便在pom.xml按一下空格然后保存,它就可以自动下载jar文件了。。

 

接下来又尝试了一下webapp模板,这回出现了很多问题

首先在右下角一直在加载Retrieving archetypes,导致特别卡,最后报错,An internal error occurred during: "Retrieving archetypes:". GC overhead limit exceeded,大概的意思就是内存溢出,看了下任务管理器在加载的时候竟然达到一千多兆,查资料都很散,纠结了一整天。。

一种是修改myeclipse.ini文件,我的修改如下:

-Xms:JVM初始分配的内存 默认是物理内存的1/64

-Xmx:JVM最大分配的内存 默认是物理内存的1/4

-XX:最大非堆内存的大小,默认是物理内存的1/4

看到有高手总结优化MyEclipse速度的主要方法:

1.修改myeclipse.ini。
2.取消自动validation
3.勾掉无用插件。
4.修改启动加载模块

但是上面这种方法没有改变我的问题

后来尝试了一下不用myeclipse自带的插件

解决:Window——priferences——Myeclipse——Maven——Archetypes

 

选择Add Remote catalog,catalog file填写:http://repo1.maven.org/maven2/archetype-catalog.xml

或者将archetype-catalog.xml 下载到本地,选择Add Local catalog,填写路径,比联网要快。。。然后点击Apply->OK。

然后选择我们新建的作为Catalog

刚刚接触maven很多东西都是知其然不知其所以然,但是有一点是conf目录下的setting.xml文件非常重要,里面设置了中央库的位置,默认是在C:\Users\xxx\.m2\repository下,但是可以根据自己的需要修改,并且在window-preferences-MyEclipse-Maven4MyEclipse-User Setting里面的Local Repository与配置文件的位置保持一致

除此之外还有代理,镜像,在下载jar文件时往往比较慢,是因为访问国外的网站,可以在镜像中做如下修改

<mirror>

<id>CN</id>
<name>OSChina Central</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<mirrorOf>central</mirrorOf>

</mirror>

方法有一堆,但在我这并没有起到太大的作用,换了工作空间也是如此,条条大路通罗马,这次直接建web project,并选择 Add maven

报了这样一个错,

Description Resource Path Location Type
Failure to transfer com.thoughtworks.xstream:xstream:pom:1.3.1 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact com.thoughtworks.xstream:xstream:pom:1.3.1 from/to central (http://repo.maven.apache.org/maven2): The operation was cancelled.pom.xml /Test line 1 Maven Configuration Problem

直到现在也没有解决,但意外的是,这个错误并没有影响运行(希望有人可以告诉我这是怎么回事,一个红叉叉,逼死强迫症啊)

 

 测试一下,在pom.xml文件中加入如下代码,

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>

右下角可以看到正在下载对应的jar到我们的库里


以下是使用RX蓝牙库连接低功耗蓝牙设备的Java代码示例,适用于Maven项目: 首先,需要在pom.xml文件添加以下依赖: ```xml <dependency> <groupId>com.polidea.rxandroidble2</groupId> <artifactId>rxandroidble</artifactId> <version>1.12.0</version> </dependency> ``` 然后,可以使用以下代码片段连接低功耗蓝牙设备: ```java import com.polidea.rxandroidble2.RxBleClient; import com.polidea.rxandroidble2.RxBleConnection; import com.polidea.rxandroidble2.exceptions.BleException; import com.polidea.rxandroidble2.scan.ScanFilter; import com.polidea.rxandroidble2.scan.ScanSettings; import io.reactivex.Observable; import io.reactivex.disposables.Disposable; public class BluetoothManager { private RxBleClient rxBleClient; private RxBleConnection rxBleConnection; private Disposable scanDisposable; public void connectToBluetoothDevice() { // 初始化RxBleClient rxBleClient = RxBleClient.create(this); // 扫描低功耗蓝牙设备 scanDisposable = rxBleClient.scanBleDevices( new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_POWER) .build(), new ScanFilter.Builder() .setDeviceName("YOUR_DEVICE_NAME") .build() ).subscribe( scanResult -> { // 找到设备 String deviceName = scanResult.getBleDevice().getName(); if (deviceName != null && deviceName.equals("YOUR_DEVICE_NAME")) { // 连接设备 connectToDevice(scanResult.getBleDevice().getMacAddress()); scanDisposable.dispose(); } }, throwable -> { // 扫描出错 } ); } private void connectToDevice(String macAddress) { // 建立低功耗蓝牙连接 Observable<RxBleConnection> connectionObservable = rxBleClient.getBleDevice(macAddress).establishConnection(false); connectionObservable.subscribe( rxBleConnection -> { // 连接成功 this.rxBleConnection = rxBleConnection; }, throwable -> { // 连接失败 } ); } public void disconnectFromBluetoothDevice() { // 断开低功耗蓝牙连接 if (rxBleConnection != null) { rxBleConnection.dispose(); } } @Override protected void onDestroy() { super.onDestroy(); // 停止扫描 if (scanDisposable != null && !scanDisposable.isDisposed()) { scanDisposable.dispose(); } } } ``` 请注意,以上示例代码仅供参考,实际使用时需要根据实际情况进行修改和调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值