Folder with jars in project

随声附和 提交于 2019-12-03 10:44:23

you can try with a classpath container, take a look here for an example .

Take a look also at the Apache IvyDE classpath container .

However adding a new library to the classpath is simple and quick as :

Right click on it ---> Build Path ---> Add To Build Path

EDIT

This lightweight plugin should do exactly what you want !

Peter Perháč

I am not too sure, but can't you have wildcards in your classpath? That way you could just edit your .classpath file for that Eclipse project and use * within a particular folder... I have not tried, i'm in a rush but that's my idea... don't know if works

EDIT here is something that you could find useful: How to use a wildcard in the classpath to add multiple jars?

Basically, just edit your .classpath file, which is where Eclipse stores the classpath settings for a project

I think the best is to use Gradle. This does not have the frustration of Maven with Eclipse. If you use STS it comes with Gradle pre-bundled.

See the link

Alexander Wood

So yeah I did this before: Use Apache Ant and specify an ant configuration that suits your build path and eclipse should be able to use it with the use from existing ant build option. Here is an example ant file you might have:

<?xml version="1.0"?>

<project name="Demo Project" basedir="." default="package">
  <!-- ================================================================= -->
  <!-- C O N F I G U R A T I O N                                         -->
  <!-- ================================================================= -->
  <!--
    Access the environment properties
    -->
  <property environment="env" />
  <!--
  TODO: Access the environment properties with a prefix of "env".
  -->
  <!--  
  Additional 3rd-party tools
   -->
  <property name="ant.home"      value="${env.ANT_HOME}"/>
  <property name="junit.home"    value="${env.JUNIT_HOME}"/>
  <property name="jmock.home"    value="${env.JMOCK_HOME}"/>
  <!--
  Project folders
  -->
  <property name="project.home"  value="${basedir}" />
  <property name="bin.dir"       value="${project.home}/bin" />
  <property name="dist.dir"      value="${project.home}/dist" />
  <property name="dist.file"     value="${dist.dir}/lab03.jar" />
  <property name="col.file"      value="${dist.dir}/lab03-col.jar" />
  <property name="src.dir"       value="${project.home}/src" />
  <property name="lib.dir"       value="${project.home}/lib" />

  <!--
  TODO: Define the classpath to be used during compilation. This should
  consist of all of the JAR files in the ${lib.dir} folder.
  -->
  <path id="project.class.path">
    <path location="${dist.file}" />
    <path location="${bin.dir}" />
    <fileset dir="${junit.home}">
    <include name="junit-4.7.jar"/>
    </fileset>
    <fileset dir="${jmock.home}">
    <include name="**/*.jar"/>
    </fileset>
    <fileset dir="${ant.home}/lib">
        <include name="**/*.jar"/>
    </fileset>
    <fileset dir="${lib.dir}">
        <include name="**/*.jar"/>
    </fileset>  
  </path>

  <!--
  TODO: Define the classpath to be used during execution. This should
  consist of all of the JAR files in the ${lib.dir} folder as well as
  ${dist.file}.
  -->
  <path id="execution.class.path">
       <path location="${bin.dir}" />
       <path location="${bin.dir}/MyPath1/MyPath" />
       <path location="${bin.dir}/MyPath1/MyPath/impl" />
       <fileset dir="${lib.dir}">
          <include name="**/*.jar"/>
       </fileset>   
  </path>

  <!-- ================================================================= -->
  <!-- C L E A N                                                         -->
  <!-- ================================================================= -->
  <target name="clean"
          description="Clean all build products">
    <delete dir="${bin.dir}" />
    <delete dir="${dist.dir}" />
  </target>

  <!-- ================================================================= -->
  <!-- C O M P I L E                                                     -->
  <!-- ================================================================= -->
  <target name="compile" 
          depends="clean,init"
            description="Compiles the application code">
    <!--
    TODO: Add the javac task. It should compile everything in ${src.dir}
    and place the output in ${bin.dir}. The classpath should refer to the
    "project.class.path" defined above.
    -->
    <javac srcdir="${src.dir}"
               destdir="${bin.dir}">
       <classpath refid="project.class.path" />
    </javac>
  </target>

  <!-- ================================================================= -->
  <!-- E N V                                                             -->
  <!-- ================================================================= -->
  <target name="env"
            description="Displays information about the build">
    <echo message="src.dir..........${src.dir}" />
    <echo message="lib.dir..........${lib.dir}" />
    <echo message="bin.dir..........${bin.dir}" />
    <echo message="dist.dir.........${dist.dir}" />
    <echo message="dist.file........${dist.file}" />
    <echo message="col.file.........${col.file}" />
    <echo message="reports.dir......${reports.dir}" />
  </target>

  <!-- ================================================================= -->
  <!-- I N I T                                                           -->
  <!-- ================================================================= -->
  <target name="init" 
          depends="env"
          description="Initializes the environment">
    <mkdir dir="${bin.dir}" />
    <mkdir dir="${dist.dir}" />
  </target>

  <!-- ================================================================= -->
  <!-- P A C K A G E                                                     -->
  <!-- ================================================================= -->
  <target name="package" 
          depends="compile"
            description="Creates the application distribution file">
    <!--
    TODO: Create a JAR file. The target JAR should be ${dist.file} and it
    should contain everything from ${bin.dir}.
    -->
    <jar destfile="${dist.file}"
           basedir="${bin.dir}"
           excludes="**/*Test*.class"
    />
  </target>

  <!-- ================================================================= -->
  <!-- P A C K A G E - C O L                                             -->
  <!-- ================================================================= -->
  <target name="package-col" 
          depends="compile"
            description="Creates the file to be submitted to COL.">
    <jar destfile="${col.file}">
      <fileset dir="${project.home}"
               includes="src/**/*.java" />
      <fileset dir="${project.home}"
               includes="lib/**/*.jar" />
      <fileset dir="${project.home}"
               includes="build.xml" />
    </jar>
  </target>

  <!-- ================================================================= -->
  <!-- R U N                                                             -->
  <!-- ================================================================= -->
  <target name="run" 
          depends="package"
            description="Executes the test file">
    <java classname="MyPath1.MyPath.FileScanner">
      <classpath refid="execution.class.path" />
      <arg value="file:///" />
    </java>
  </target>
</project>

AND Here is a link with someone with a similair problem using ant to solve his classpath problems. Ant is portable so it can actually be set up anywhere and you can also use global variables to keep all systems consistent or just use relative paths. And there is also an eclipse ant plugin

just try including

<classpathentry kind="lib" path="lib/spring/4.2.1" including="*.jar"/>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!