标签: classpath

Maven 提供的范围和 Eclipse 运行时类路径

我的 eclipse 类路径与 m2e 插件有问题。我有一个项目依赖于我工作区中的其他项目。我已将这些依赖项添加为提供范围的 Maven 依赖项。我希望范围执行以下操作:提供编译依赖项,但将它们排除在运行时类路径中。因为在运行时,这些类应该从文件夹内的 jar 加载。

但是 eclipse 类路径包括我在项目 pom.xml 中提供的每个依赖项。Eclipse 似乎忽略了提供的范围。有没有办法从运行时类路径中排除那些?

问候

eclipse classpath maven m2e

5
推荐指数
1
解决办法
6125
查看次数

类路径中的远程 jars

抱歉,也许这个问题太愚蠢或已经回答了,但我找不到。

我想知道是否有一些已知的 Java 类加载器能够接受类路径中的远程文件,即像 CLASSPATH="http://somewhere.net/library.jar:..." 这样的条目。

请注意,我不是在谈论小程序或 Java Web Start。考虑一个可以使用不同后端(例如 MySQL、Oracle)的应用程序,我想根据用户的后端偏好在 shell 脚本中准备类路径,并让类加载器下载所需的jar(本例中的 jdbc 驱动程序)来自分发服务器。我也不是在谈论 Maven(用户只是获得二进制分发版,我不想强​​迫他们从源代码构建他们需要的东西)。

java remoteobject classpath classloader

5
推荐指数
1
解决办法
4496
查看次数

'java -jar' 获取传递依赖项吗?

如果我执行一个 jar:

java -jar foo.jar
Run Code Online (Sandbox Code Playgroud)

并在其清单的属性中foo.jar声明依赖项,清单中定义的 jar 是否会添加到类路径中?bar.jarClass-Pathbar.jar

MANIFEST.MF在foo.bar包含:

Class-Path: bar.jar
Run Code Online (Sandbox Code Playgroud)

MANIFEST.MF在bar.bar包含:

Class-Path: baz.jar
Run Code Online (Sandbox Code Playgroud)

baz.jar运行时是否添加到类路径中java -jar foo.jar?

java classpath

5
推荐指数
0
解决办法
318
查看次数

使用Jython的标准Python模块的ImportError(在JAR文件中)

我已经实现了一个包含Jython的Java应用程序来运行Python脚本.当我从IDE(Eclipse或IDEA)运行该应用程序时,一切正常,Python脚本得到正确处理.

但是,当我将所有内容打包到一个JAR文件(待发布)中,包括该jython.jar文件时,一旦Java应用程序尝试运行第一个Python脚本,我就会收到以下错误:

ImportError: No module named os
Run Code Online (Sandbox Code Playgroud)

因此,似乎Lib找不到包含所有标准Python模块的文件夹.我检查了jython.jarJava应用程序的JAR文件中包含的文件,它确实包含了该Lib文件夹.实际上,这是jython.jar我从IDE运行应用程序时使用的同一文件.

我知道可以指定-Dpython.path参数,但我不知道在这里设置什么.我怎么能指的Lib是在文件夹内,jython.jar这是主要的应用程序的JAR文件中的文件?

java jython jar classpath

5
推荐指数
1
解决办法
739
查看次数

ANT checkstyle任务:无法找到/访问AST节点

在尝试使用ANT设置Hudson来构建我们的项目时,我偶然发现了类似于此问题的问题.但是,建议的解决方案对我不起作用.

我通过ANT任务调用checkstyle来设置它自己的类路径.

<target name="checkstyle" depends="init, staticAnalysisInit">
    <mkdir dir="${checkstyle.dir}"/>
    <path id="checkstyle.classpath">
        <fileset dir="${env.CHECKSTYLE_HOME}">
            <include name="*.jar"/>
            <exclude name="*all.jar"/>
            <!-- already bundled with ANT distributions and causes problems -->
            <exclude name="antlr*.jar"/> 
        </fileset>
    </path>
    <property name="chkstyl.cp" refid="checkstyle.classpath"/>
    <echo>Checkstyle classpath: ${chkstyl.cp}</echo>
    <taskdef name="checkstyle" 
             classpathref="checkstyle.classpath" 
             classname="com.puppycrawl.tools.checkstyle.CheckStyleTask"/>
    <checkstyle config="${env.CHECKSTYLE_HOME}/sun_checks.xml"
                failOnViolation="false">
        <formatter type="xml" toFile="${checkstyle.dir}/checkstyle.xml"/>
        <fileset dir="${src.dir}">
            <include name="**/*.java"/>
        </fileset>
    </checkstyle>
</target>
Run Code Online (Sandbox Code Playgroud)

它给了我以下输出:

init:

staticAnalysisInit:

checkstyle:
     [echo] Checkstyle classpath: C:\Program Files (x86)\Checkstyle\checkstyle-5.6\checkstyle-5.6.jar;C:\Program Files (x86)\Checkstyle\checkstyle-5.6\commons-beanutils-core-1.8.3.jar;C:\Program Files (x86)\Checkstyle\checkstyle-5.6\commons-cli-1.2.jar;C:\Program Files (x86)\Checkstyle\checkstyle-5.6\commons-logging-1.1.1.jar;C:\Program Files (x86)\Checkstyle\checkstyle-5.6\google-collections-1.0.jar
[checkstyle] Running Checkstyle 5.6 on 1025 files …
Run Code Online (Sandbox Code Playgroud)

java ant classpath checkstyle

5
推荐指数
1
解决办法
1387
查看次数

Postgres:没有为jdbc找到合适的驱动程序

我知道这可能是这里发布的问题的重复.对不起.这是我为数据库连接编写的代码

 try{
            Class.forName("org.postgresql.Driver");     
       }

       catch(ClassNotFoundException e)
       {
          e.printStackTrace();
       }

       try{
           String URL = "jdbc:posgresql://localhost:5432/postgres";
           String USER = "postgres";
           String PASS = "postgres";
           Connection conn = DriverManager.getConnection(URL, USER, PASS);
           Statement st = conn.createStatement();
           ResultSet rs = st.executeQuery("Select * from employee");
           while(rs.next()){
               System.out.println(rs.getString(1));
           }

       }

       catch(SQLException es){
           es.printStackTrace();
       }
Run Code Online (Sandbox Code Playgroud)

运行此代码时,我得到以下异常:

java.sql.SQLException: No suitable driver found for jdbc:posgresql://localhost:5432/postgres
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at ManageEmployee.main(ManageEmployee.java:60)
Run Code Online (Sandbox Code Playgroud)

我在eclipse中构建了这个项目并添加了外部jar的postgres

如果它可能有帮助,这是.classpath文件

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
        <attributes>
            <attribute name="owner.project.facets" value="java"/>
        </attributes> …
Run Code Online (Sandbox Code Playgroud)

java postgresql jdbc classpath eclipse-classpath

5
推荐指数
1
解决办法
2万
查看次数

testng无法从ant加载测试类

我正在尝试从Ant运行TestNG测试.阅读手册后,我想出了:

<taskdef name="testng" classname="org.testng.TestNGAntTask" classpath="../../lib/testng-6.8.1.jar"/>
<target name="testng" depends="compile-tests" description="Run testng test suite">      

<fileset id="mixed.tests" dir="${bin.main}">
    <include name="**/*Test.*"/>
</fileset>

<testng mode="mixed" classfilesetref="mixed.tests" 
    verbose="5"
    failureProperty="tests.failed" outputdir="/tmp/report">
    <classpath>
        <fileset dir="../../lib" includes="*.jar"/>
        <fileset dir="../../java/bin/" includes="**/*.class"/>
    <fileset dir="/home/y/lib/jars" excludes="junit*jar,messagebus-disc-parent.jar" includes="**/*.jar" description="all jars installed by dependent pacakges" />
    </classpath>
</testng>
Run Code Online (Sandbox Code Playgroud)

当我运行它失败时:

   [testng] 'org.testng.TestNG'
   [testng] '@/tmp/testng8260935716887369607'
   [testng]
   [testng] The ' characters around the executable and arguments are
   [testng] not part of the command.
   [testng] Exception in thread "main" org.testng.TestNGException:
   [testng] Cannot load class from file: …
Run Code Online (Sandbox Code Playgroud)

java ant testng classpath

5
推荐指数
1
解决办法
3936
查看次数

git - 推送java .classpath文件?

我有一个小的java项目,我和朋友一起工作.我们都使用eclipse与egit插件和github进行版本管理.

除了JRE库,我们使用javafx和RXTX库.由于我们都需要库,我们将它们放在项目的lib文件夹中.然后我们设置.classpath来引用项目中的库,并将.classpath推送到github.

那时,我们意识到,不同的计算机需要不同的库,并且在CVS中使用.classpath文件可能是个坏主意.

所以我的问题是,这里的最佳做法是什么?提交.classpath文件似乎是一个坏主意,但是我希望能够控制项目中使用的库,因此为库jar提供其他项目文件可能是一个好主意; 然后,拉动项目的人可以轻松地将他的系统的jar添加到类路径中.但是,因此我必须为每个系统(win32,win64,linux,...)提供javafx和RXTX库,这似乎也不是最好的事情.

我觉得这可能已经被问过,但是我找不到令人满意的问题/答案.

java git classpath libraries

5
推荐指数
1
解决办法
4738
查看次数

Spring PropertyPlaceHolder Java Config外部属性文件

所以这必须是一些愚蠢的错误,我无法通过.我正在尝试外部化我的属性文件,该文件目前放在我的用户主目录中.我正在使用@PropertySource这样加载属性文件:

@Configuration
@PropertySources(value = { @PropertySource("file:#{systemProperties['user.home']}/.invoice/config.properties") })
public class PropertiesConfig {

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertiesPlaceHolderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }
}
Run Code Online (Sandbox Code Playgroud)

但不幸的是,这不是加载属性文件.投掷FileNotFoundException.但是,如果我改变路径:

@PropertySources(value = { @PropertySource("file:/home/rohit/.invoice/config.properties") })
Run Code Online (Sandbox Code Playgroud)

它工作正常.这就是早期路径解决的路径.我已经记录下来进行验证.所以在我看来,SpEL没有在@PropertySource注释中得到评估.它应该以这种方式工作吗?

如果是,那么还有其他方法可以读取外部属性文件/home/rohit吗?出于显而易见的原因,我不想给出绝对的道路.我想避免延长PropertyPlaceHolderConfigurer课程.

我尝试的另一个选项是将/home/rohit/.invoice文件夹添加到tomcat类路径.但似乎Spring不使用System Classpath来解析classpath:后缀.有关于此的任何指示?

java spring properties classpath spring-el

5
推荐指数
1
解决办法
2351
查看次数

带有sbt和scala.swing的NoClassDefFoundError

我是JVM的新手,所以如果这是一个常见的问题我会道歉.我在OSX上使用Scala(2.12)和sbt 0.13.13.

我正在开发一个依赖于GUI库scala.swing(2.10.x)的小应用程序.我几乎立即用示例代码(http://otfried.org/scala/index_28.html)遇到了运行时问题.

具体来说,在调用时,sbt run我得到一个带有以下内容的stacktrace:

[error] (run-main-0) java.lang.NoClassDefFoundError: scala/Proxy$class
java.lang.NoClassDefFoundError: scala/Proxy$class
    at scala.swing.Window.<init>(Window.scala:25)
    at scala.swing.Frame.<init>(RichWindow.scala:75)
    at scala.swing.MainFrame.<init>(MainFrame.scala:19)
Run Code Online (Sandbox Code Playgroud)

(Proxy似乎是scala stdlib中的类/特征)

读取SO和其他地方表明,当编译时出现的代码随后无法在运行时定位时,通常会发出这种异常.实际上,代码编译得很好,只有在运行代码时才会出现问题.

我发现的所有建议都是classpath为了解决这些问题.但是,如果sbt要相信控制台,我的编译时和运行时类路径是相同的:

> show compile:fullClasspath
[info] * Attributed(/Users/chris/Projects/thing2/target/scala-2.12/classes)
[info] * Attributed(/Users/chris/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.12.1.jar)
[info] * Attributed(/Users/chris/.ivy2/cache/org.scala-lang/scala-swing/jars/scala-swing-2.10.6.jar)
[success] Total time: 0 s, completed Dec 24, 2016 7:01:15 PM
> show runtime:fullClasspath
[info] * Attributed(/Users/chris/Projects/thing2/target/scala-2.12/classes)
[info] * Attributed(/Users/chris/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.12.1.jar)
[info] * Attributed(/Users/chris/.ivy2/cache/org.scala-lang/scala-swing/jars/scala-swing-2.10.6.jar)
[success] Total time: 0 s, completed Dec 24, 2016 7:01:19 PM
Run Code Online (Sandbox Code Playgroud)

所以,我发现自己处于一种法医僵局.关于在哪里寻找下一个的任何建议将非常感激.为清楚起见,这只发生在 …

swing scala classpath sbt

5
推荐指数
1
解决办法
1045
查看次数