gpt4 book ai didi

java - Maven:复制到 FTP 抛出 java.io.IOException:非法搜索

转载 作者:IT王子 更新时间:2023-10-29 00:07:53 24 4
gpt4 key购买 nike

我有一个桌面(centos 7.1)和一个ftp服务器(GF4在这里)。我想在 maven 构建到 ftp 服务器后复制文件(女巫由 nautilus 安装)但是我得到这个:

at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error copying artifact from /home/myuser/temp/target/temp.jar to /run/user/1000/gvfs/ftp:host=X.X.X.X,port=XXX/glassfish4/glassfish/domains/domain3/autodeploy/bundles/temp.jar
at org.apache.maven.plugin.dependency.AbstractDependencyMojo.copyFile(AbstractDependencyMojo.java:232)
at org.apache.maven.plugin.dependency.fromConfiguration.CopyMojo.copyArtifact(CopyMojo.java:133)
at org.apache.maven.plugin.dependency.fromConfiguration.CopyMojo.doExecute(CopyMojo.java:111)
at org.apache.maven.plugin.dependency.AbstractDependencyMojo.execute(AbstractDependencyMojo.java:167)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Caused by: java.io.IOException: Illegal seek
at sun.nio.ch.FileDispatcherImpl.pwrite0(Native Method)
at sun.nio.ch.FileDispatcherImpl.pwrite(FileDispatcherImpl.java:66)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:89)
at sun.nio.ch.IOUtil.write(IOUtil.java:51)
at sun.nio.ch.FileChannelImpl.writeInternal(FileChannelImpl.java:745)
at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:731)
at sun.nio.ch.FileChannelImpl.transferFromFileChannel(FileChannelImpl.java:603)
at sun.nio.ch.FileChannelImpl.transferFrom(FileChannelImpl.java:675)
at org.codehaus.plexus.util.FileUtils.doCopyFile(FileUtils.java:1077)
at org.codehaus.plexus.util.FileUtils.copyFile(FileUtils.java:1049)
at org.apache.maven.plugin.dependency.AbstractDependencyMojo.copyFile(AbstractDependencyMojo.java:228)
... 24 more

文件夹/run/user/1000/gvfs/ftp:host=X.X.X.X,port=XXX/glassfish4/glassfish/domains/domain3/autodeploy/bundles/temp.jar 中的文件已创建,但其大小为 0。此外,当我进行手动复制时:

cp /home/myuser/temp/target/temp.jar /run/user/1000/gvfs/ftp:host=X.X.X.X,port=XXX/glassfish4/glassfish/domains/domain3/autodeploy/bundles/

一切正常。如何解决?
EDIT1
我创建了一个仅包含激活器的空 osgi 项目。这是 pom

<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>com.mycompany</groupId>
<artifactId>hworld</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>

<name>hworld</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Activator>com.mycompany.hworld.Activator</Bundle-Activator>
<Export-Package/>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>${project.packaging}</type>
<outputDirectory>HERE IS FOLDER NAME</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>build-for-felix</id>
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
<version>4.0.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>compile</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<pathconvert property="plugins.jars" pathsep="${path.separator}">
<path refid="maven.runtime.classpath"/>
<map from="${project.build.directory}${file.separator}classes" to=""/>
</pathconvert>
<pathconvert pathsep=" " property="bundles">
<path path="${plugins.jars}"/>
<mapper>
<chainedmapper>
<flattenmapper/>
<globmapper from="*" to="file:modules/*" casesensitive="no"/>
</chainedmapper>
</mapper>
</pathconvert>
<propertyfile file="${project.build.directory}/config.properties">
<entry key="felix.auto.start" value="${bundles} file:modules/${project.build.finalName}.jar"/>
<entry key="org.osgi.framework.bootdelegation" value="*"/>
</propertyfile>
<copy file="${maven.dependency.org.apache.felix.org.apache.felix.main.jar.path}" tofile="${project.build.directory}/felix.jar"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>create-executable-jar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${basedir}/src/main/assembly/felix.xml</descriptor>
</descriptors>
<finalName>${project.build.finalName}</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>run-on-felix</id>
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
<version>4.0.3</version>
<scope>provided</scope>
</dependency>
<!-- org.apache.felix:org.apache.felix.gogo.shell:0.6.1 useless from Maven since stdin is swallowed -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<configuration>
<target>
<property name="vm.args" value=""/>
<pathconvert property="plugins.jars" pathsep="${path.separator}">
<path refid="maven.runtime.classpath"/>
<map from="${project.build.directory}${file.separator}classes" to=""/>
</pathconvert>
<makeurl property="urls" separator=" ">
<path path="${plugins.jars}"/>
<path location="${project.build.directory}/${project.build.finalName}.jar"/>
</makeurl>
<propertyfile file="${project.build.directory}/run.properties">
<entry key="felix.auto.start" value="${urls}"/>
<entry key="felix.auto.deploy.action" value="uninstall,install,update,start"/>
<entry key="org.osgi.framework.storage" value="${project.build.directory}${file.separator}felix-cache"/>
<entry key="org.osgi.framework.bootdelegation" value="*"/>
</propertyfile>
<makeurl property="run.properties.url" file="${project.build.directory}/run.properties"/>
<java fork="true" jar="${maven.dependency.org.apache.felix.org.apache.felix.main.jar.path}">
<sysproperty key="felix.config.properties" value="${run.properties.url}"/>
<jvmarg line="${vm.args}"/>
</java>
</target>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

结果相同 - 在目标文件夹中创建了 hworld-1.0.-SNAPSHOT.jar,但其大小为 0。

最佳答案

使用 maven-dependency-plugincopy 目标,您可以复制插件运行时可用的依赖项,这是在二进制 Artifact 之前您的项目位于 target 文件夹中。

要将项目的二进制文件上传到 FTP,请使用以下命令:

  • 在你的 pom 中:
<project>
...
<distributionManagement>
<repository>
<id>ftp-repository</id>
<url>ftp://repository.mycompany.com/repository</url>
</repository>
</distributionManagement>

<build>
<extensions>
<!-- Enabling the use of FTP -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>2.9</version>
</extension>
</extensions>
</build>
...
</project>
  • 在你的~.m2/settings.xml
<settings>
...
<servers>
<server>
<id>ftp-repository</id>
<username>user</username>
<password>pass</password>
</server>
</servers>
...
</settings>

请注意,pom 中的 id 与设置中的 id 匹配。

关于java - Maven:复制到 FTP 抛出 java.io.IOException:非法搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30076271/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com