我试图编译和打包我的Java应用程序,但我在尝试指定我的本地存储库时遇到问题,我将在其中使用我的jar作为依赖项.我在'/ home/test/lib'中存储了我的应用程序所需的所有jar.我的build.gradle文件如下所示:
apply plugin:'application'
apply plugin:'java'
apply plugin:'idea'
def repositoryPath = '/home/test/lib'
repositories {
repositoryPath
}
dependencies {
"org.springframework:spring-orm:3.0.2.RELEASE"
"org.springframework:spring-context-support:3.0.2.RELEASE"
'commons-dbcp:commons-dbcp:1.4'
'org.apache.ibatis:ibatis-sqlmap:2.3.4.726'
'commons-dbutils:commons-dbutils:1.3'
'joda-time:joda-time:1.6'
'commons-lang:commons-lang:2.5'
'com.google.collections:google-collections:1.0'
}
jar {
baseName = 'testJar'
}
mainClassName = "com.some.test.testRunner"
Run Code Online (Sandbox Code Playgroud)
当我运行gradle build时,我得到"package*not exists"错误.
我的假设是gradle没有在我的lib文件夹中找到必需的外部jar.有人可以指出我在这里做错了什么.
谢谢
我正在使用Eclipse,并且我使用SWT编写了一个Java应用程序.当Eclipse编译我的程序时,它将我的主文件重命名为4个不同的文件,如下所示:
当我从命令行运行这个程序时,我得到了
找不到主类:MainFile.class.程序将会退出.
我真的不明白为什么会这样.
我正在尝试在我的java应用程序中编译java文件,但是它们需要使用不在类路径中的其他类进行编译.所以在我的代码中我放入了如下选项:
Iterable options = Arrays.asList("-classpath \"/path/to/some/classes\"");
Run Code Online (Sandbox Code Playgroud)
然后我像这样编译:
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, options, null, compilationUnits1);
Run Code Online (Sandbox Code Playgroud)
我得到的确切错误是这样的:
java.lang.IllegalArgumentException:invalid flag:-classpath"/ path/to/some/classes"
我是否必须以另一种方式将其他库添加到classspath中?
标题说明了一切;
"mvn compile"产生大量错误,这是第一个:
[错误] $ HOME/workspace/JavaExamplePBServiceCall/src/main/java/example/ServicecallPiqi.java:[13,23]错误:';' 预期
手动编译产生100个错误,这是第一个:
javac -cp $ HOME/.m2/repository/com/google/protobuf/protobuf-java/2.4.1/protobuf-java-2.4.1.jar ServicecallPiqi.java
ServicecallPiqi.java:535: error: cannot find symbol
public static com.google.protobuf.Parser<params> PARSER =
^
symbol: class Parser
location: package com.google.protobuf
Run Code Online (Sandbox Code Playgroud)
ServicecallPiqi.java的开头:
package example;
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: pb_piqi_out/servicecall.piqi.proto
public final class ServicecallPiqi {
private ServicecallPiqi() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
}
/**
* Protobuf enum {@code cast_type}
*/
public enum cast_type implements
// ^^^^^^^^^^^^^ OFFENDING line
Run Code Online (Sandbox Code Playgroud)
这是我的pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" …Run Code Online (Sandbox Code Playgroud) 我正在尝试遵循Apache TikaJAXRS 看起来非常简单的编译指令.我在Windows 8.1 64bit上运行.
好.我已经完成了第1步,但是我在第2步遇到了磕磕绊.显然这里有一些未编写的先决条件,所以我试图解决它们如下:
C:\Program Files\Java\jdk1.8.0_25.C:\Program Files\Java\jdk1.8.0_25\binC:\apache-maven-3.2.5\bin然后从tika-1.7目录(src下载的zip的内容)我运行mvn install.在吐出下面粘贴的错误输出之前,编译快乐地进行几分钟,此时编译似乎冻结.
问题看起来可能就是这个问题 - https://issues.apache.org/jira/browse/TIKA-1276 那里有一些关于重新创建捆绑包并修改文件以解决问题的讨论,但我坦率地说发现奇怪的是,为了获得Tika的工作副本,我必须跳过这样的箍 - 没有提供二进制分发!
我需要做些什么才能解决这个编译问题?
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.apache.tika.bundle.BundleIT
[main] INFO org.ops4j.pax.exam.spi.DefaultExamSystem - Pax Exam System (Version: 2.2.0) created.
Jan 19, 2015 11:48:40 AM org.ops4j.pax.url.mvn.internal.AetherBasedResolver resolve
INFO: Resolved (org.junit:com.springsource.org.junit:jar:4.4.0) as C:\Users\Jason\.m2\repository\org\junit\com.springsource.org.junit\4.4.0\com.springsource.org.junit-4.4.0.jar
ERROR: Bundle org.ops4j.pax.exam.rbc [1] Error …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个安装 (bash) 脚本,我需要在其中检查用户是否安装了 java 1.8。
最明显的方法是调用
javac -version | grep 1.8
Run Code Online (Sandbox Code Playgroud)
,但由于一些奇怪的原因 javac (和 java) -version 输出不能被重定向 - 不能通过 |、> 或 >> - 在第一种情况下,第二个程序没有得到任何输入,在第二个和第三个中,执行命令后输出文件为空。我试图在三台不同的机器上检查它,结果在每台机器上都是一样的。
那是什么原因呢?有没有其他方法可以检查java版本?
要使用java反射获取方法参数名称,我们必须使用"-parameters"选项编译Java类,但是当我使用VM Arguments从eclipse执行此操作时,我在控制台中收到以下错误.
Unrecognized option: -parameters
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Run Code Online (Sandbox Code Playgroud)
我在我的系统中运行Java 8.我错过了什么?
这是一个初学者的问题.我试图从带有参数的cmd运行java程序.这是我的班级:
public class Test{
public static void main(String[] args){
System.out.println("This is a test");
System.out.println(args.length);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以成功运行它而不需要参数.如何在程序中添加示例5和6作为参数?
我发现所有其他答案只是运行程序.我已经知道该怎么做了.我无法找到如何使用参数运行程序.
我在尝试在 Mac 上的 IntelliJ 上构建我的项目时遇到了这样的错误。
Error:(12, 39) java: diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
Error:(122, 48) java: method references are not supported in -source 1.5
(use -source 8 or higher to enable method references)
Error:(124, 51) java: lambda expressions are not supported in -source 1.5
(use -source 8 or higher to enable lambda expressions)
Run Code Online (Sandbox Code Playgroud)
查看此站点上的其他答案,这与项目语言级别太低有关。但是,我的设置如下:
似乎我选择了正确的选项,但我仍然遇到相同的错误。我该如何解决这些问题。
如果我使用 JDK 11.0.1,这是日志的第一部分:
Information:java: JPS build failed to load optimized file manager for …Run Code Online (Sandbox Code Playgroud)