Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven NoClassDefFoundError使用ivy。JAR未添加到类路径_Maven_Ivy_Ivyde - Fatal编程技术网

Maven NoClassDefFoundError使用ivy。JAR未添加到类路径

Maven NoClassDefFoundError使用ivy。JAR未添加到类路径,maven,ivy,ivyde,Maven,Ivy,Ivyde,似乎我从maven repo中提取的jar没有被放入我的java类路径中。我以为常春藤贮藏室会处理这个 每当我在eclipse中或eclipse外部运行一个类时,我都会得到NoClassDefFoundError。 它编译得很好,但在运行时不起作用。我的dependency conf设置为runtime->default,所以我认为这会起作用 下面是我使用的文件。我做错什么了吗 ivy.xml <?xml version="1.0" encoding="UTF-8"?> <iv

似乎我从maven repo中提取的jar没有被放入我的java类路径中。我以为常春藤贮藏室会处理这个

每当我在eclipse中或eclipse外部运行一个类时,我都会得到NoClassDefFoundError。 它编译得很好,但在运行时不起作用。我的dependency conf设置为runtime->default,所以我认为这会起作用

下面是我使用的文件。我做错什么了吗

ivy.xml

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:m="http://ant.apache.org/ivy/maven"
            xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
    <info organisation="org_test" module="mod_test" />
    <configurations>
    <conf name="compile" description="Required to compile application" />
    <conf name="runtime" description="Additional run-time dependencies" extends="compile" />
    <conf name="test" description="Required for test only" extends="runtime" />
    </configurations>
    <publications>
        <artifact ext="jar" />
        <artifact ext="pom" />
    </publications>
    <dependencies>
        <dependency org="org.apache.solr" name="solr-core" rev="3.5.0" conf="runtime->default" />
        <dependency org="org.apache.solr" name="solr-solrj" rev="3.6.0" conf="runtime->default" />
    </dependencies>
</ivy-module>

ivysettings.xml

<?xml version="1.0" encoding="UTF-8"?>
<ivysettings>
    <settings defaultResolver="chained" />
    <property name="maven.pattern" value="[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]" />
    <property name="public.repo.url" value="http://${repo.host}:${repo.port}/nexus/content/groups/public/" override="false" />
    <property name="repo.host" value="localhost" override="false" />
    <property name="repo.port" value="8081" override="false" />
    <property name="repo.path" value="nexus/content/repositories" override="false" />
    <property name="retrieve.resolver" value="chained" override="false" />
    <resolvers>
        <ibiblio name="public" m2compatible="true" root="${public.repo.url}" />
        <chain name="chained" returnFirst="false">
            <resolver ref="public" />
        </chain>
    </resolvers>
</ivysettings>

common.xml

<project name="common" xmlns:ivy="antlib:org.apache.ivy.ant">

    <dirname property="ivy-support.build.dir" file="${ant.file.ivy-support}" />
    <property name="ivy-support.lib.dir" location="${ivy-support.build.dir}/ivy" />
    <property name="ivy.settings.filename" value="ivysettings.xml" />

    <property name="ivy.install.version" value="2.1.0-rc2" />
    <condition property="ivy.home" value="${env.IVY_HOME}">
      <isset property="env.IVY_HOME" />
    </condition>
    <property name="ivy.home" value="${user.home}/.ant" />
    <property name="ivy.jar.dir" value="${ivy.home}/lib" />
    <property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />

    <target name="download-ivy" unless="offline">

        <mkdir dir="${ivy.jar.dir}"/>
        <!-- download Ivy from web site so that it can be used even without any special installation -->
        <get src="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" 
             dest="${ivy.jar.file}" usetimestamp="true"/>
    </target>

    <target name="init-ivy" depends="download-ivy">
      <!-- try to load ivy here from ivy home, in case the user has not already dropped
              it into ant's lib dir (note that the latter copy will always take precedence).
              We will not fail as long as local lib dir exists (it may be empty) and
              ivy is in at least one of ant's lib dir or the local lib dir. -->
        <path id="ivy.lib.path">
            <fileset dir="${ivy.jar.dir}" includes="*.jar"/>
        </path>
        <taskdef resource="org/apache/ivy/ant/antlib.xml"
                 uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
    </target>


    <path id="ivy.lib.path">
        <fileset dir="${ivy-support.lib.dir}" includes="*.jar" />
    </path>
    <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path" loaderref="ivy.lib.loader" />

    <ivy:settings file="${ivy-support.build.dir}/${ivy.settings.filename}" />

    <property name="should.clean.ivy.cache" value="false" />

    <dirname property="ivy-support.build.dir" file="${ant.file.ivy-support}" />
    <property name="ivy-support.lib.dir" location="${ivy-support.build.dir}/ivy" />
    <property name="ivy.settings.filename" value="ivysettings.xml" />

    <path id="ivy.lib.path">
        <fileset dir="${ivy-support.lib.dir}" includes="*.jar" />
    </path>
    <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path" loaderref="ivy.lib.loader" />

    <ivy:settings file="${ivy-support.build.dir}/${ivy.settings.filename}" />

    <target name="clean-ivy-cache" if="clean.ivy.cache.istrue">
        <ivy:cleancache />
    </target>
</project>

build.xml

<project name="main" xmlns:ivy="antlib:org.apache.ivy.ant" default="compile">
    <description>Testing Script</description>
    <import file="common.xml" />

    <!--
    ================
    Build properties
    ================
    -->
    <property name="src.dir" location="src/org"/>
    <property name="build.dir" location="build"/>
    <property name="classes.dir" location="${build.dir}/classes"/>
    <property name="test.classes.dir" location="${build.dir}/test-classes"/>
    <property name="ivy.reports.dir"  location="${build.dir}/ivy-reports"/>
    <property name="test.reports.dir"  location="${build.dir}/test-reports"/>

    <!--
    ===========
    Build setup
    ===========
    -->
    <target name="init">
        <ivy:resolve file="ivy.xml" />

        <ivy:report todir='${ivy.reports.dir}' graph='false' xml='false'/>

        <ivy:cachepath pathid="compile.path" conf="compile"/>
        <ivy:cachepath pathid="runtime.path" conf="runtime"/>
        <ivy:cachepath pathid="test.path"    conf="test"/>

        <mkdir dir="${classes.dir}"/>
        <mkdir dir="${test.classes.dir}"/>
        <mkdir dir="${test.reports.dir}"/>
    </target>

    <!--
    ===============
    Compile target
    ===============
    -->
    <target name="compile" depends="init">
        <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="true" debug="true" classpathref="runtime.path"/>
    </target>

    <!--
    =====================
    Build and run targets
    =====================
    -->
    <target name="run" depends="init-ivy">
        <java classname="org">
            <classpath>
                <path refid="runtime.path"/>
                <pathelement location="${classes.dir}"/>
            </classpath>
        </java>
    </target>

    <!--
    =============
    Clean targets
    =============
    -->
    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>

    <target name="clean-all" depends="clean">
        <ivy:cleancache/>
    </target>

</project>

测试脚本

是的,常春藤中有一个……这就是原因。看看人们给出的bug及其解决方案。这对我有用。解决方案是您必须为您的项目禁用保存时编译选项。检查这是否有帮助。

您的错误到底是什么?我注意到您的“run”目标有一个“depends”属性,它调用与常春藤相关的目标,但不编译代码。这就是问题所在吗?由于未编译本地源,运行时缺少类?最后,您声明它在Eclipse中不起作用。这是错误的,因为ivy是一个ANT插件。你试过从命令行运行ANT吗?